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!

VBSCRIPT - Get attribute for parent node 1

Status
Not open for further replies.

dranium

Technical User
Mar 9, 2009
15
CA
Hello,

I will try to describe the best I can what I am trying to accomplish. I am parsing out this xml file into a javascript file. I have everything working and I am at my last step where I need to place the menu in the right spot. I will show you the important bits of code + xml to describe the problem.

I am currently returning the nodeName but what I want to do is return the attribute id="id01". I tried using the paremeter getAttribute("id") but my script keeps giving me an error. Is it possible to return the id="id01" with out looking up thje parentNode twice? Any help would be greatly appreciated, I have been trying to figure this out for way to long. Thank you in advanced!

Code:
mycode.vbs

Set xmlDoc = CreateObject("Msxml2.DOMDocument") 
xmlDoc.load("menu.xml") 

set n = xmlDoc.getElementsByTagName("title")(5)
msgbox(n.text) 
set p_node = n.parentNode
msgbox(p_node.nodeName) //returns item
set pp_node = p_node.parentNode
msgbox(pp_node.nodeName) //returns item2

Code:
menu.xml

<?xml version="1.0" encoding="UTF-8"?>
<test>     
	 <title>My menu</title>
	<item2 id="id01" isvisible="true">
		<title>Questions</title>
		<item1 id="id02" isvisible="true">
			<title>Sub menu of question</title>
			<item id="id03" idref="idr01" isvisible="true">
				<title>Question 1</title>
			</item>
			<item id="id04" idref="idr02" isvisible="true">
				<title>Question 2</title>
			</item>
        </item1>
        <item id="id05" idref="idr03" isvisible="true">
			<title>Content 1</title>
        </item>
        <item id="id06" idref="idr04" isvisible="true">
			<title>Content 2</title>
		</item>
	 </item2>
</test>

 
[0] comment in vbs is apostrophe, not double slash. That is why you get error all the time I guess.

[1] nothing wrong by this.
[tt] msgbox pp_node.getAttribute("id")[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top