Solved

Select multiple nodes using XPATH

Posted on 2006-11-10
5
3,725 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

Independent Software Vendors: 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 Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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