Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Problem with an XPATH statement in JScript

From: MichaelD@-----------.---------.---
To: NULL
Date: 7/7/2006 9:55:00 AM


"Martin Honnen" wrote:

> 
> 
> Michael D. wrote:
> 
> > I'm trying to select a node by it's position number in a JScript statement.  
> > However, the below line gives me an error:
> > 
> > myInfoNode2 = xmlCourse.selectSingleNode("position()=3");
> 
> I think you want
>    xmlCourse.selectSingleNode("node()[position()=3]")
> or simply
>    xmlCourse.selectSingleNode("node()[3]")
> Depening on what kind of node xmlCourse is you also want to look for 
> descendants and not only children e.g.
>    xmlCourse.selectSingleNode(".//node()[3]")
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 

Thanks, that was helpful.  I'm not quite where I want to be yet though.  I'm 
trying to create a sort of navigating scheme for an online course template, I 
was hoping to get an XPATH statement that could be used to get to any node 
regardless of it's type or position in the document.

All the nodes (except the document element) will have a "link" attribute 
with a webpage url (the example below is just dummy data, so all the link 
attributes are not unique)

Given the example XML data below, could I construct an XPATH that would give 
me (for example):

xmlCourse.selectSingleNode(".//node()[1]") =  the <courseInfo> node
xmlCourse.selectSingleNode(".//node()[2]") = the first <module> node
xmlCourse.selectSingleNode(".//node()[3]") = the first<lesson> under the 
first <module>
xmlCourse.selectSingleNode(".//node()[4]") = the first <topic> under the 
first <lesson>
xmlCourse.selectSingleNode(".//node()[5]") = the first <page> under the 
first <topic>
xmlCourse.selectSingleNode(".//node()[6]") = the SECOND <page>
xmlCourse.selectSingleNode(".//node()[7]") = the THIRD <page>

etc, etc...

Here is a simple example of the XML I'm trying to navigate:

<courseInfo courseName="Test Course" courseCode="009999">
  <module name="Module One" link="module1.html">
    <lesson name="M1 Lesson One" link="lesson1.html">
       <topic link="topic1.html" name="Module One Lesson One Topic One">
         <page link="link.html" name="M1L1T1Page1"/>
         <page link="link.html" name="M1L1T1Page2"/>
        <page link="link.html" name="M1L1T1 Page Three"/>
        <page link="link.html" name="M1L1T1Page Four"/>
    </topic>
   <topic name="Module One Lesson One Topic Two" link="topic2.html">
        <page name="Page One" link="link.html"/>
    </topic>
 </lesson>
  <lesson name="Module One Lesson Two" link="link.html">
    <topic name="TOPIC ONE IN THAT MODULE" link="link.html">
         <page name="one" link="link.html"/>
         <page name="two" link="link.html"/>
   </topic>
 </lesson>
</module>
</courseInfo>



transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent