[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How can I set the XML document type in Gambas


Hi

I know how to read a xml structure but for a new project I need to generate one, which is new to me. As a first simple exercise and by using gb.xml I tried below Gambas snippet but was quickly stuck because I didn't find any way to declare the xml document type ..

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE database SYSTEM "example.dtd"  <------ can't find a way to insert this
<database>
 <user id="101">
  <name>
   Max Mustermann
  </name>
  <email>
   max@xxxxxxxxxxx
  </email>
 </user>
</database>

Is there a way to insert such doctype declaration?

Best regards

Claus

Used snippet:

  Dim hDoc As New XmlDocument
  Dim eRoot As XmlElement
  Dim eUser As XmlElement
  Dim eData As XmlElement

  ' 1. Generate a root-element for the XmlDocument
  eRoot = hDoc.CreateElement("database")
  hDoc.Root = eRoot

  ' 2. Add a child-element (here a user)
  eUser = hDoc.CreateElement("user")
  eUser.SetAttribute("id", "101") ' setting the attribut
  eRoot.AppendChild(eUser)

  ' 3. Adding nested elements
  eData = hDoc.CreateElement("name")
  eData.TextContent = "Max Mustermann"
  eUser.AppendChild(eData)

  eData = hDoc.CreateElement("email")
  eData.TextContent = "max@xxxxxxxxxxx"
  eUser.AppendChild(eData)

  ' 4. save the XML-Structure as file
  hDoc.Save(User.Home &/ "user.xml")

  ' 5. Show it in the IDE console
  Print "\n" & hDoc.ToString(True)



Follow-Ups:
Re: How can I set the XML document type in GambasLee <t.lee.davidson@xxxxxxxxx>