some basic xml needs - having trouble

Discussion in 'Scripting' started by James, Sep 5, 2008.

  1. James

    James Guest

    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.createProcessingInstruction("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>
    ---------------------------------------------------
     
    James, Sep 5, 2008
    #1
    1. Advertisements

  2. James

    James Guest

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

    <way embarrased>thanks.</way embarrased>


    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/
     
    James, Sep 5, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.