Results 1 to 7 of 7

Thread: xml document formats and VB MSXML2

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497

    xml document formats and VB MSXML2

    I can use Visual Basic's MSXML2 objects to make an xml file like this:

    <root>
    <record>
    <JobID>126</JobID>
    <Session>1</Session>
    <WorkStation>LARCHMONT</WorkStation>
    <JobSource>dbaexchis\</JobSource>
    </record></root>

    But how do I use that library to make a file like this:

    <root>
    <record JobID="126" Session="1" WorkStation="LARCHMONT" JobSource="dbaexchis\">
    </record></root>

    What I desire, is it considered "attribute-centric"?
    end war
    stop greed

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Use the XML Nodes setAttribute method (or getAttribute to read).

    VB Code:
    1. Set xmlFolder = xml.createElement("source")
    2. xmlFolder.setAttribute "folder", strFolder
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    JoshT, I do not have .setAttribute as an intellisense choice when I do what you suggested. I also don't understand what you suggested.
    end war
    stop greed

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Would you like to borrow my copy of "An Idiots Guide to Understanding JoshT?"
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Eh Heh...

    VB Code:
    1. 'root is the XML DOMDocument object that corresponds to your root tag
    2. Dim root as MSXML2.DOMDocument
    3. Dim xmlRecord as MSXML2.IXMLDOMElement
    4. 'code for opening up the xml document and setting root goes here
    5.  
    6. Set xmlRecord = root.createElement("record") 'make the <record /> tag
    7. xmlRecord.setAttribute "JobID", "126"
    8. xmlRecord.setAttribute "Workstation", "LARCHMONT"
    9. 'set the rest of the attributes...
    10.  
    11. root.AppendChild xmRecord 'add the new <record /> to the xml file
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    I had to tweak that a bit but I got your point. I just don't want everything to be attributes. I want a new node for each record, with attributes beneath it. But you have me an idea, perhaps it's the way I'm writing the nodes to the document. Thanks for your help.
    end war
    stop greed

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    What I had to do was

    Set xRecordNode = xDoc.CreateNode(NODE_ELEMENT,"record","")
    set xRecordNode = xParentNode.appendChild(xRecordNode)

    ' And do this for each "field" of the record
    Set xFieldNode = xDoc.CreateNode(NODE_ELEMENT,"JOBId","")
    set xFieldNode = xParentNode.appendChild(xFieldNode)
    end war
    stop greed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width