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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parseing XML

Status
Not open for further replies.

mgid

Programmer
Oct 2, 2000
87
US
I'm very new to xml. This some xml generated by saving an ADO recordset to xml in a client side script. I need to parse it for display on another page, and I having a hard time with the MSXML DOM object. Does anyone have any examples that might illustrate how to get at this.

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row content='eltOnly'
rs:CommandTimeout='60' rs:updatable='true'> <s:AttributeType name='ColName' rs:number='1'
rs:nullable='true' rs:writeunknown='true'> <s:datatype dt:type='string'
dt:maxLength='100'/>
</s:AttributeType>
<s:AttributeType name='FriendlyName' rs:number='2'
rs:nullable='true' rs:writeunknown='true'> <s:datatype dt:type='string'
dt:maxLength='100'/>
</s:AttributeType>
<s:AttributeType name='Aggregate' rs:number='3'
rs:nullable='true' rs:writeunknown='true'>
<s:datatype dt:type='boolean'
dt:maxLength='2' rs:fixedlength='true'/> </s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ColName='accountnumber' FriendlyName='Acc
Number' Aggregate='False'/>
<z:row ColName='acc_id' FriendlyName='Account Id'
Aggregate='False'/>
<z:row ColName='type' FriendlyName='Account Type'
Aggregate='False'/>
<z:row ColName='accountvalue' FriendlyName='Account
Value' Aggregate='True'/>
<z:row ColName='branchid' FriendlyName='Branch Id'
Aggregate='False'/>
</rs:data>
</xml>
 
Sorry, that's &quot;Parsing XML&quot;.
 
missing quote mark

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly'

if that is not your question then can you rephrase it?

after inserting the missing quote mark, I had no problem loading the XML.

Code:
Dim oDOM As DOMDocument30

Set oDOM = New DOMDocument30
If oDOM.Load(&quot;c:\test.xml&quot;) Then
  MsgBox &quot;ok&quot;
Else
  MsgBox oDOM.parseError.reason, vbExclamation
End If
Set oDOM = Nothing
 
I think it loaded correctly. I just couln't access any of the data. I would like to see how you would use the DOM object to get at the data by field name held in the xml.

Thanks.
 
You have the addition problem of namespace prefixes on your data types. You should check your parser documentation for how to get namespace prefixed elements out of an XML Document. The three parsers I've looked at do this in very different ways. Which DOM parser are you using?

Under MSXML 4.0...

Set detailDoc = CreateObject(&quot;MSXML2.DOMDocument.4.0&quot;)
detailDoc.setProperty &quot;SelectionNamespaces&quot;, xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'

You may now select nodes using the prefix &quot;s&quot; for the given namespace.

Set attrTypes = detailDoc.selectSingleNode(&quot;//s:AttributeType&quot;)

I haven't had to set &quot;SelectionNamespaces&quot; to allow more than one prefix to be selectable before. I'm not certain how to do this, but the above can at least get you going.

Good Luck,
Uura
~~~~
&quot;Common sense tells you that the world is flat.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top