[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I set the XML document type in Gambas
[Thread Prev] | [Thread Next]
- Subject: Re: How can I set the XML document type in Gambas
- From: Lee <t.lee.davidson@xxxxxxxxx>
- Date: Sun, 27 Sep 2026 15:56:48 -0400
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 9/27/26 8:25 AM, Claus Dietrich wrote:
HiI 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
A DTD (Document Type Definition) node can be created as an XmlTextNode. However, I see no way to add an XmlNode to the document tree (only an XmlElement) with either XmlDocument or XmlWriter.
Even if the DTD is added to the document by manipulating the content directly (as with the code immediately below), the DTD node is filtered out of the tree apparently being seen as invalid:
[code]
Public Sub Main()
Dim sXmlContent As String = ""
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<database>\n"
" <user id=\"101\">\n"
" <name>\n"
" Max Mustermann\n"
" </name>\n"
" <email>\n"
" max@xxxxxxxxxxx\n"
" </email>\n"
" </user>\n"
"</database>"
Dim hDoc As New XmlDocument
Dim saContent As String[]
hDoc.FromString(sXmlContent)
Print hDoc.Content & "\n------"
saContent = Split(hDoc.Content, "\n")
saContent.Add("<!DOCTYPE database SYSTEM \"example.dtd\">", 1)
Print saContent.Join("\n") & "\n------"
hDoc.Content = saContent.Join("\n")
Print hDoc.Content
End
[/code]
XmlWriter does have a .DTD property, but for some odd reason it is read-only. XmlDocument should also have a DTD property, and
it should be read/write for both classes.
I have submitted numerous bug reports regarding the XML components (the latest being #3047), and none have received any response from Adrien Prokopowicz. It seems, as Benoît stated, Adrien has disappeared.
I think the XML components should be rewritten. Unfortunately from my perspective, they are written in C++ and so I have difficulty deciphering them.
-- Lee --- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ---- --- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----
| Re: How can I set the XML document type in Gambas | Claus Dietrich <claus.dietrich@xxxxxxxxxx> |
| How can I set the XML document type in Gambas | Claus Dietrich <claus.dietrich@xxxxxxxxxx> |