Problem while retrieving data based on condition

Discussion in 'XML' started by Pathik, Apr 2, 2007.

  1. Pathik

    Pathik Guest

    Hi All,

    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>


    I am new to xml. I don't know how to write xpath for such a thing.
    Please take a look at and give me suggestions how i should i approach
    this problem.

    Thanks and Regards,
    Pathik
     
    Pathik, Apr 2, 2007
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Apr 2, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel

    while condition

    Daniel, May 20, 2005, in forum: VHDL
    Replies:
    7
    Views:
    3,531
    Ralf Hildebrandt
    May 23, 2005
  2. =?Utf-8?B?UFZWMzA=?=

    Out of Memory exception while retrieving data

    =?Utf-8?B?UFZWMzA=?=, Jul 28, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,046
    Alvin Bruney [MVP]
    Jul 28, 2004
  3. =?Utf-8?B?U3VyZXNo?=

    how to reload data based on condition

    =?Utf-8?B?U3VyZXNo?=, Nov 25, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    448
    =?Utf-8?B?c3VyZXNoIGthbm5hbg==?=
    Nov 25, 2004
  4. -
    Replies:
    12
    Views:
    697
    Remon van Vliet
    Jun 15, 2005
  5. Bill W.
    Replies:
    13
    Views:
    295
    Phillip Gawlowski
    May 9, 2011
Loading...

Share This Page