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

Search XML File with XMLDOM

Status
Not open for further replies.

Byourself

Programmer
Jul 5, 2002
18
0
0
IL
Hi,

I have a question. I couldn't find documentation about it on the net so I hope the pro's here will help.

Well, I have an xml which looks like:
<MyXMLTree>
<FirstName>
<width>200px</width>
<DefValue>Your name here</DefValue>
</FirstName>
</MyXMLTree>

Anyway, I'd like to know how can I get only the width and DefValue values which are under FirstName only and not from a different parent node.

I have to do it with XMLDOM because I'm programming it with the old ASP...

Thanks a lot!
Shay ---------------
&quot;Young and hostile, but not stupid&quot; (Blink 182)
 
Well you could specify a loop that would loop for each object in a list generated by element.selectNodes(&quot;FirstName&quot;) and you would have access to the children of all the Firstname nodes. I would post code by I haven't done XMLDOM in ASP in a few months and might get your more lost than you already were :p
-Tarwn &quot;Customer Support is an art not a service&quot; - marketing saying
&quot;So are most other forms of torture&quot; - programmers response
(The Wiz Biz - Rick Cook)
 
Hmmmm... Could you add a short sample code?

XMLDOM is really bad documented and I can't find nothing about it...

Thanks ---------------
&quot;Young and hostile, but not stupid&quot; (Blink 182)
 
Here's a short example of at least one way to do it:

To get <width> and <DefValue> of <FirstName>
Create the objects which point to the correct nodes in your tree (as shown above), and then read out the &quot;text&quot; property to get the value:

-----------
Code:
Set objRoot     = objDOM.documentElement
Set objWidth    = objRoot.getElementsByTagName(&quot;FirstName/width&quot;)
Set objDefValue = objRoot.getElementsByTagName(&quot;FirstName/DefValue&quot;)

strWidth = objWidth(0).text
strDefValue = objDefValue(0).text
----------

If you have multiple <FirstName> elements in your document, or if you have multiple <width> and/or <DefValue> elements in <FirstName>, that puts a different spin on it....

Here's an online reference for XMLDOM - Hope this helps.
Ciao, K----------------
&quot;If you were supposed to understand it, we wouldn't call it code&quot; - FedEx
 
Accidentally omitted 2 lines in above example....

---------------------------
Set objDOM = CreateObject(&quot;Microsoft.XMLDOM&quot;)
objDOM.Load(&quot;path/file.xml&quot;)
Set objRoot = objDOM.documentElement
Set objWidth = objRoot.getElementsByTagName(&quot;FirstName/width&quot;)
Set objDefValue = objRoot.getElementsByTagName(&quot;FirstName/DefValue&quot;)

strWidth = objWidth(0).text
strDefValue = objDefValue(0).text
---------- Hope this helps.
Ciao, K----------------
&quot;If you were supposed to understand it, we wouldn't call it code&quot; - FedEx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top