Solved

Select multiple nodes using XPATH

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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. 
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now