|
-
Apr 29th, 2002, 01:31 PM
#1
Thread Starter
Hyperactive Member
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"?
-
Apr 29th, 2002, 01:49 PM
#2
Black Cat
Use the XML Nodes setAttribute method (or getAttribute to read).
VB Code:
Set xmlFolder = xml.createElement("source")
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.
-
Apr 29th, 2002, 01:54 PM
#3
Thread Starter
Hyperactive Member
JoshT, I do not have .setAttribute as an intellisense choice when I do what you suggested. I also don't understand what you suggested.
-
Apr 29th, 2002, 02:12 PM
#4
Stuck in the 80s
Would you like to borrow my copy of "An Idiots Guide to Understanding JoshT?"
-
Apr 29th, 2002, 02:27 PM
#5
Black Cat
Eh Heh...
VB Code:
'root is the XML DOMDocument object that corresponds to your root tag
Dim root as MSXML2.DOMDocument
Dim xmlRecord as MSXML2.IXMLDOMElement
'code for opening up the xml document and setting root goes here
Set xmlRecord = root.createElement("record") 'make the <record /> tag
xmlRecord.setAttribute "JobID", "126"
xmlRecord.setAttribute "Workstation", "LARCHMONT"
'set the rest of the attributes...
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.
-
Apr 29th, 2002, 02:44 PM
#6
Thread Starter
Hyperactive Member
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.
-
May 9th, 2002, 08:21 PM
#7
Thread Starter
Hyperactive Member
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|