Solved

Xpath 1.0 function for Exists

Posted on 2013-05-16
3
357 Views
Last Modified: 2013-05-21
I have the following XML:

        <A>
          <B>
            <Amount>5000</Amount>
            <Start>60</Start>
            <End>65</End>
          </B>
          <B>
            <Amount>3000</Amount>
            <Start>63</Start>
          </B>
	  <B>
            <Amount>1234</Amount>
            <Start>61</Start>
            <End>67</End>
          </B>
        </A>

Open in new window


I want to create two Xpath queries that return me the 'start' and 'end' elements for each B.
Problem is, I now end up with two arrays of different lengths: (60;63;61) and (65;67).
I want to be able to detect which B doesn't have an end-element.

Therefore I should use a function like 'exists' or something like that, but I can only use the Xpath 1.0 library.
Anybody that can help me with this?
0
Comment
Question by:adiemeer
[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
  • 2
3 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39170796
//B[not(End)]
0
 

Author Comment

by:adiemeer
ID: 39170816
Thanks, this is helping me.
But how do I now construct the array of length 3? (With a dummy for the second element, f.i 65;999;67)
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39170825
you can't do that purely in XPath1.
XPath1 is for addressing a node(set)
The construction of the array happens outside XPath1.
That is where you need to add a dummy

I suggest that you make an array of B nodes and pull out either End or default from it in constructing a second array, whichever programming language you are using

boils down to ... " what programming language are you using?"

you could have a pass using XSLT that introduces a End element having value 999
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

Suggested Solutions

Title # Comments Views Activity
XSL - substring between 2 commas 12 33
ASP Classic - Read XML File inner content 10 73
Sql case statement to calculate totals 5 55
SP result not being displayed 5 69
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 …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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