Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select multiple nodes using XPATH

Posted on 2006-11-10
5
Medium Priority
?
3,728 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 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. 
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

660 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