Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > some basic xml needs - having trouble

Reply
Thread Tools Display Modes

some basic xml needs - having trouble

 
 
James
Guest
Posts: n/a

 
      09-05-2008
Hi, I'm just looking to save some information to file in xml format using
vbscipt/wsh. Below is the testing code I started to just learn the basics of
creating the xml structure. The code produces file but all the text nodes
wind up together under one element instead of in there proper place. What am
I doing wrong here?

------my test code------------------
Dim xmldoc
Set xmldoc = CreateObject("msxml2.domdocument")

xmldoc.async = False
xmlDoc.appendChild(xmlDoc.createProcessingInstruct ion("xml","version=""1.0"""))

Set oRootElement = xmldoc.createElement("NetworkCardConfigs")
Set elementAdapter = xmldoc.createElement("Adapter")
elementAdapter.setAttribute "MAC", "testMAC"


Set elementIP = xmldoc.createElement("IP")
Set txtNodeIP = xmldoc.createTextNode("test ip info")
Set elementSM = xmldoc.createElement("SM")
Set txtNodeSM = xmldoc.createTextNode("test sm info")
Set elementDG = xmldoc.createElement("DG")
Set txtNodeDG = xmldoc.createTextNode("test dg info")

xmldoc.appendChild(oRootElement)
oRootElement.appendChild(elementAdapter)
elementAdapter.appendChild(elementIP)
elementIP.appendChild(txtNodeIP)
elementAdapter.appendChild(elementSM)
elementIP.appendChild(txtNodeSM)
elementAdapter.appendChild(elementDG)
elementIP.appendChild(txtNodeDG)

xmldoc.save("testy.xml")
-------------------------
------ output from my test code - testy.xml contents -----------------

<?xml version="1.0" ?>
<NetworkCardConfigs>
<Adapter MAC="testMAC">
<IP>test ip infotest sm infotest dg info</IP>
<SM />
<DG />
</Adapter>
</NetworkCardConfigs>
---------------------------------------------------


 
Reply With Quote
 
 
 
 
James
Guest
Posts: n/a

 
      09-05-2008
WOW! I don't smoke crack, I swear. I'm going straight to the eye doctor!

<way embarrased>thanks.</way embarrased>


"Tom Lavedas" <> wrote in message
news:bba1f4a5-e107-4a76-8214-...
On Sep 5, 10:40 am, "James" <no...@nowhere.com> wrote:
> Hi, I'm just looking to save some information to file in xml format using
> vbscipt/wsh. Below is the testing code I started to just learn the basics
> of
> creating the xml structure. The code produces file but all the text nodes
> wind up together under one element instead of in there proper place. What
> am
> I doing wrong here?
>
> ------my test code------------------
> Dim xmldoc
> Set xmldoc = CreateObject("msxml2.domdocument")
>
> xmldoc.async = False
> xmlDoc.appendChild(xmlDoc.createProcessingInstruct ion("xml","version=""1.0"""))
>
> Set oRootElement = xmldoc.createElement("NetworkCardConfigs")
> Set elementAdapter = xmldoc.createElement("Adapter")
> elementAdapter.setAttribute "MAC", "testMAC"
>
> Set elementIP = xmldoc.createElement("IP")
> Set txtNodeIP = xmldoc.createTextNode("test ip info")
> Set elementSM = xmldoc.createElement("SM")
> Set txtNodeSM = xmldoc.createTextNode("test sm info")
> Set elementDG = xmldoc.createElement("DG")
> Set txtNodeDG = xmldoc.createTextNode("test dg info")
>
> xmldoc.appendChild(oRootElement)
> oRootElement.appendChild(elementAdapter)
> elementAdapter.appendChild(elementIP)
> elementIP.appendChild(txtNodeIP)
> elementAdapter.appendChild(elementSM)
> elementIP.appendChild(txtNodeSM)
> elementAdapter.appendChild(elementDG)
> elementIP.appendChild(txtNodeDG)
>
> xmldoc.save("testy.xml")
> -------------------------
> ------ output from my test code - testy.xml contents -----------------
>
> <?xml version="1.0" ?>
> <NetworkCardConfigs>
> <Adapter MAC="testMAC">
> <IP>test ip infotest sm infotest dg info</IP>
> <SM />
> <DG />
> </Adapter>
> </NetworkCardConfigs>
> ---------------------------------------------------


Try changing the element names to match the nodes you really want to
address in these two lines of code ...

elementSM.appendChild(txtNodeSM) ' not elementIP

elementDG.appendChild(txtNodeDG) ' not elementIP

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Game Crazy Site Login Trouble--Visual Basic--C++--Vista 64-bit? Susan Internet Explorer 10 07-30-2009 06:26 PM
Re: Game Crazy Site Login Trouble--Visual Basic--C++--Vista 64-bit? Susan Windows Vista General Discussion 4 07-30-2009 06:26 PM
Re: Game Crazy Site Login Trouble--Visual Basic--C++--Vista 64-bit? PA Bear [MS MVP] Windows Vista General Discussion 3 06-27-2009 09:22 AM
Media Computer - Basic, Basic Questions PT Windows Media Center 3 06-09-2008 09:41 PM
have window vista basic.understand basic don't have fax & scan jay sureka Windows Vista Printing / Faxing / Scanning 4 01-07-2008 06:02 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59