Solved

Select multiple nodes using XPATH

Posted on 2006-11-10
5
3,726 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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