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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where does the XML version tag get added?

Status
Not open for further replies.

Mthales

Technical User
Joined
Feb 27, 2004
Messages
1,181
Location
GB
Hi there,

I am trying to work with an MSXML2.DOMDocument30. I define my variable then I set it as a new instance of MSXML2.DOMDocument30 and start adding nodes to it then save the document.

When I examine the resulting document I was expecting to see <?xml version="1.0"?> at the top of the file and then all the nodes I added but it's not there.

So my question is simply how do I add the version tag to the top of the document?

Thanks for any help

M [wiggle]
 
It mave not be correct, but it works for me
Code:
Dim xmlPI As IXMLDOMProcessingInstruction

With New DOMDocument40
    'Creete Processing instruction
    strVersion = "version=" & Chr$(34) & "1.0" & Chr$(34) & " encoding=" & Chr$(34) & "UTF-8" & Chr$(34)

    Set xmlPI = .createProcessingInstruction("xml", strVersion)
    .appendChild xmlPI
end with
'don't froget to write file...

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks very much for that Matt it does work fine. However I did however think there was a way that added in this tag without having to explicitly define it like this.

I'm asking because my code used to produce xml with this tag at the start and now I've done something and it doesn't any more. I'd never added it like this before and thought there was some way I was getting the newly created xml document to put this in for itself.

Does anyone have any ideas?
Thanks

M [wiggle]
 
Have you tried adding attributes to the documentElement property? It's the root element of the document.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I do it the way Matt shows - or at least a minor variant as:

Set objPI = objDOM.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'")
objDOM.insertBefore objPI, objDOM.childNodes(0)

I'm pretty certain I got this from an XML site rather than coming up with it myself for a change, but I'm afraid I can't remember where so I can't credit it properly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top