Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSXML v2 DOCTYPE

Status
Not open for further replies.

ynyrjones

Programmer
Mar 7, 2007
2
GB
Hi Everyone,

I'm trying to write an application in VB6 to export some XML using MS XML DOM version 2. I'm trying to get output the following line but I am having some trouble...

<!DOCTYPE NMLoader SYSTEM "standardX05.dtd">

within the structure...

<?xml version="1.0"?>
<!DOCTYPE NMLoader SYSTEM "standardX05.dtd">
<NMLoader>
<ele1>1</ele1>
<ele2>2</ele2>
</NMloader>

I've tried using the createCDataSection Method but it puts "[" around the tag and only appears to work within the <NMLoader> tags anyway, not at the start of the document. I've tried using the createTextNode method too but to no avail.

The nature of this post stems from a problem I've had trying to write the !DOCTYPE element when creating XML files "on the fly". This is because the DOCTYPE element is apparently read only. A few posts on the net mention that the only way to get around this problem is to first loadXML and then append the necessary DOCTYPE element.

I have attempted to load in the XML using the loadXML method. But I can't seem to append a DOCTYPE, I'm stuck again.

There's an IXMLDOMDocumentType object that I believe to be the DOCTYPE object that I need, I'm just struggling to see how and where I can append it.

The first question really is: Is this the way to be solving this problem? And if not, what is the best method of overcoming it? Installing a later version of ms xml?

The second question is: If this is the way to solve the problem, could you please post some code to help me out! I'm really struggling!

Many Thanks
Ynyr
 
This is how you do it. (Make it early bind you want.)
[tt]
set oxmldoc=createobject("msxml2.domdocument.4.0")
with oxmldoc
.async=false
.validateonparse=false
.load "your_xml_doc.xml"
.loadxml "<?xml version=""1.0""?><!DOCTYPE NMLoader SYSTEM ""standardX05.dtd"">" & .documentElement.xml
.save "your_new_doc.xml"
end with
set oxmldoc=nothing
[/tt]
A couple of comments is of order.
[1] The above supposed the original "your_xml_doc.xml" is well-formed. Otherwise, you insert control on parseerror before loadxml.
[2] Anything like processing instructions and comments before the root will be lost. Hence, to use that form, you better place all those within the root.
[3] You can do the same with an xslt document which is essentially an identity transformation, but with an attribute doctype-system specified in the output element.
[tt]<xsl:eek:utput method="xml" doctype-system="standardX05.dtd" />[/tt]
The transformation will be accomplished through transform() method or transformtoobject() method. This method will plug the hole of inconvenience mentioned in [2]. But I won't elaborate this.
 
Thanks tsuji :)

I'll give that a try now. I've looked in a lot of places for an answer! I'll post back to let you know how its gone.

Ynyr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top