XML processing question

Discussion in 'XML' started by Rahul, Feb 21, 2008.

  1. Rahul

    Rahul Guest

    Hi,

    I want to do the following

    <A>
    <B attr1="1" attr2="2">
    .................
    </B>
    <B attr1="4" attr2="5">
    .................
    </B>

    ......................
    <B attr1="1" attr2="2">
    <repeat attr1="1" attr2="2> // Here I want to insert the
    first <B> element which had attr=1 and attr=2
    </B>
    </A>

    The problem is to replace the <repeat> element with the sibling of its
    parent (repeat will always be done for the sibling of parent of
    repeat) which has the given attribute values.

    Can I do this in DOM, or I need to pre process the XML using XSD.

    Thanks in advance
    Rahul
     
    Rahul, Feb 21, 2008
    #1
    1. Advertising

  2. Rahul

    Pavel Lepin Guest

    Rahul <> wrote in
    <>:
    > <A>
    > <B attr1="1" attr2="2">
    > .................
    > </B>
    > <B attr1="4" attr2="5">
    > .................
    > </B>
    >
    > ......................
    > <B attr1="1" attr2="2">
    > <repeat attr1="1" attr2="2> // Here I want
    > to insert the
    > first <B> element which had attr=1 and attr=2
    > </B>
    > </A>
    >
    > The problem is to replace the <repeat> element with the
    > sibling of its parent (repeat will always be done for the
    > sibling of parent of repeat) which has the given attribute
    > values.
    >
    > Can I do this in DOM, or I need to pre process the XML
    > using XSD.


    I fail to see how a schema definition would help you with
    this, unless you're using some sort of sophisticated
    schema-based data-binding library.

    Your problem can certainly be solved by iterating over the
    DOM, but if your API allows you to evaluate XPath
    expressions (which is quite likely) this would be even
    easier. Transforming your document using XSLT before
    stuffing it into your application is a viable option too.

    Which one of these options would be better in your case is
    impossible to tell without knowing a lot more about your
    platform, your documents and the actual problem you're
    facing.

    --
    When all you have is a transformation engine, everything
    looks like a tree.
     
    Pavel Lepin, Feb 21, 2008
    #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. Bomb Diggy
    Replies:
    0
    Views:
    472
    Bomb Diggy
    Jul 28, 2004
  2. Oleg  Paraschenko
    Replies:
    0
    Views:
    396
    Oleg Paraschenko
    Jun 6, 2005
  3. knorth
    Replies:
    0
    Views:
    381
    knorth
    Nov 5, 2005
  4. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    541
    Michael Foord
    Sep 17, 2004
  5. Tomasz Wegrzanowski

    magic/xml library for easy XML processing

    Tomasz Wegrzanowski, Aug 5, 2006, in forum: Ruby
    Replies:
    5
    Views:
    107
    Tomasz Wegrzanowski
    Aug 6, 2006
Loading...

Share This Page