Solved

Select multiple nodes using XPATH

Posted on 2006-11-10
5
3,723 Views
Last Modified: 2010-10-05
I have this javascript code, but it only retrieve all MarkMethod nodes that met the condition of MarkObjectType=TEXT
How do i change the code to include also MarkObjectText,  MarkInfo nodes in the result?

var MatchingNodes=theRoot.selectNodes("/ArrayOfMarkTemplate/MarkTemplate/MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkMethod/
 var outMarkHtml2 ="<table id='MarkText2'>"
                           for (i=0;i<MatchingNodes.length;i++){
                         
                            outMarkHtml2+= "<tr><td>" + MatchingNodes.item(i).text + "</td></tr>";
                         
                           }
                           outMarkHtml2+="</table>";    
                           document.write(outMarkHtml2);
                            }


This is my XML :

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfMarkTemplate>
  <MarkTemplate>
    <MarkType>MARKTYPE001</MarkType>
    <ImageId>854</ImageId>
    <MarkingObjects>
      <MarkObject>
        <MarkObjectType>TEXT</MarkObjectType>
        <ObjectText>TEXT001</ObjectText>
        <MarkMethod></MarkMethod>
        <MarkInfo>Info</MarkInfo>
      </MarkObject>
      <MarkObject>
        <MarkObjectType>TEXT</MarkObjectType>
        <ObjectText>TEXT002</ObjectText>
        <MarkInfo>Info</MarkInfo>
       </MarkObject>
      <MarkObject>
        <MarkObjectType>TEXT</MarkObjectType>
        <ObjectText>TEXT003</ObjectText>
       <MarkInfo>Info001</MarkInfo>      
      </MarkObject>
      <MarkObject>
        <MarkObjectType>GRAPHIC</MarkObjectType>
        <ObjectText>GRAPHIC001</ObjectText>
       <MarkInfo>Info004</MarkInfo>
      </MarkObject>
    </MarkingObjects>
  </MarkTemplate>
  <MarkTemplate>
   ......
  </MarkTemplate>

</ArrayOfMarkTemplate>

0
Comment
Question by:sherly
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17912924
Hi sherly,
> theRoot.selectNodes("/ArrayOfMarkTemplate/MarkTemplate/MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkMethod/

you can use the union symbol "|"

theRoot.selectNodes("//MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkMethod |
//MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkObjectText |
//MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkInfo")


Cheers!
0
 
LVL 2

Author Comment

by:sherly
ID: 17913752
Hi Gertone, this returns me all MarkObject of every MarkElement with MarkObjectType='TEXT'. What if I want to display all the MarkObject with MarkObjectType='TEXT' of the first MarkTemplate only?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 200 total points
ID: 17913858
MarkTemplate/

theRoot.selectNodes("//MarkTemplate[1]/MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkMethod |
//MarkTemplate[1]/MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkObjectText |
//MarkTemplate[1]/MarkingObjects/MarkObject[MarkObjectType='TEXT']/MarkInfo")
0
 
LVL 2

Author Comment

by:sherly
ID: 17920996
thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17921042
welcome
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question