Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Problem while retrieving data based on condition

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 4/2/2007 1:40:00 PM

Pathik wrote:

> I have to get the values of "reading" and "value" elements of context
> Person/Category/Group/ser.These values must be on condition
> based,means I have to get the values of "reading" and "value" if
> entity="abc" and value="1" , and entity= "def" and value="2" at the
> Person/Category/Group/series/Key.
> 
> My xml source file is as follows.
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Person>
>      <Category>
>          <Group>
>              <series>
>                  <Key>
>                      <Main entity="abc" value="1"></Main>
>                      <Main entity="def" value="2"></Main>
>                  </Key>
>              </series>
>              <ser>
>                  <reading>age</reading>
>                  <value>100</value>
>              </ser>
>              <ser>
>                  <reading>height</reading>
>                  <value>6</value>
>              </ser>
>              <ser>
>                  <reading>weight</reading>
>                  <value>80</value>
>              </ser>
>          </Group>
>        </Category>
>   </Person>

It is not clear to me which ser/reading and ser/value element you are 
looking for as I don't see the relationship between the series/Key/Main 
elements and those ser elements. Are you looking for all reading and 
value elements if the document contains the Main elements meeting your 
conditions on the attributes?

> I am new to xml. I don't know how to write xpath for such a thing.

You need to learn about predicates which can be put into square brackets 
e.g.
   /Person/Category/Group
selects all Group elements with that path, then you can add a predicate 
to filter them in square brackets e.g.
   /Person/Category/Group[series/Key[Main[@entity = 'abc' and @value = 
'1'] and Main[@entity = 'def' and @value = '2']]]
filters based on series/Key descendants for which another condition 
holds, there is a Main child meeting your first attribute condition and 
there is a Main child meeting the second attribute condition.
Then if you are looking for ser/reading desdendant elements of that 
Group element you can add
   /Person/Category/Group[series/Key[Main[@entity = 'abc' and @value = 
'1'] and Main[@entity = 'def' and @value = '2']]]/ser/reading



-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent