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!

MS XMLDOM Parser 1

Status
Not open for further replies.

agoeddeke

Programmer
Jul 23, 2002
201
US
Here is an example of XML I need to produce:

Code:
<?xml version="1.0"?>
<MyMessage 
   xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL]
   xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
 <MyAck/>
</MyMessage>

My question is how can I add the schema references (xmlns:xsd, xmlns:xsi) using only the XMLDOM parser? I figured out that I can add the version line using oxmldom.CreateProcessingInstruction, but the schema line stumps me.

If I try adding "xmlns:xsd" as an attribute to the <MyMessage> element, it tells me I cannot modify a read-only value when I go to set it's value.

Any help would be... well... helpful!

Thanks,
Andy
 
You can simply use setAttribute to do that. This is how you can do it---with the demo, it will be clear.
[tt]
set oparser=createobject("msxml2.domdocument")
set oprlg=oparser.createProcessingInstruction("xml", "version='1.0'")
oparser.insertBefore oprlg, oparser.childnodes.item(0)
set oprlg=nothing
set oroot=oparser.createElement("MyMessage")
with oroot
.setAttribute "xml:xsd"," .setAttribute "xmlns:xsl","end with
set oparser.documentElement=oroot
set onode=oparser.createTextNode(vbcrlf & vbtab)
oroot.appendChild onode
set onode=oparser.createElement("MyAck")
oroot.appendChild onode
set onode=oparser.createTextNode(vbcrlf)
oroot.appendChild onode

'[green]save to your path[/green]
oparser.save [green]"d:\test\MyMessage.xml"[/green]

set onode=nothing
set oroot=nothing
set oparser=nothing
[/tt]
I'm using classic vbs. You can follow the same pattern for other languages as long as it uses msxml2.domdocument.
 
Thank you tsuji. Your example was very helpful and solved my problem. The XML looks perfect now.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top