extract inner xml...

Discussion in 'XML' started by Loocek, Mar 17, 2009.

  1. Loocek

    Loocek Guest

    Hi,

    I need to find and extract inner xml and save as String.
    I cannot find that functionality in any [DOM,SAX,STAX] xml parser in java...
    I was able to do it in DOM by serializing Node - but is stupid solution....
    Would you give me any suggestion [or part of example] how to do it?
    My XMLs are quite big... [100k]

    Thanks for any help

    Regards
    Pawel Z
     
    Loocek, Mar 17, 2009
    #1
    1. Advertising

  2. Loocek wrote:

    > I need to find and extract inner xml and save as String.
    > I cannot find that functionality in any [DOM,SAX,STAX] xml parser in
    > java...
    > I was able to do it in DOM by serializing Node - but is stupid solution....


    I am not sure why it is a stupid solution. If you want the inner XML
    then you will have to serialize the child nodes, unless the object model
    is not already providing properties like InnerXml (as for instance the
    ..NET framework's DOM model does:
    http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.innerxml.aspx)

    If you are using the W3C DOM then Level 3 has serialization features
    http://www.w3.org/TR/DOM-Level-3-LS/
    I think Java 5 and 6 implement that. In the browser world of the DOM
    only Opera supports it but Mozilla has XmlSerializer and IE/MSXML have
    the xml property on XML DOM nodes.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 17, 2009
    #2
    1. Advertising

  3. Loocek

    Loocek Guest

    Hi again,

    Martin Honnen wrote:
    > Loocek wrote:
    >
    >> I need to find and extract inner xml and save as String.
    >> I cannot find that functionality in any [DOM,SAX,STAX] xml parser in
    >> java...
    >> I was able to do it in DOM by serializing Node - but is stupid
    >> solution....

    >
    > I am not sure why it is a stupid solution.

    A "raw" input stream of data is read by parser. It creates objects in
    memory, next base on the object - we create a new "raw" stream that is
    exactly substring of original string. It waste memory and cpu....


    If you want the inner XML
    > then you will have to serialize the child nodes, unless the object model
    > is not already providing properties like InnerXml (as for instance the
    > .NET framework's DOM model does:
    > http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.innerxml.aspx)

    I know it is simple. One method call ...
    >
    > If you are using the W3C DOM then Level 3 has serialization features
    > http://www.w3.org/TR/DOM-Level-3-LS/
    > I think Java 5 and 6 implement that. In the browser world of the DOM
    > only Opera supports it but Mozilla has XmlSerializer and IE/MSXML have
    > the xml property on XML DOM nodes.



    Thanks for fast answer.
    Regards
    Pawel Zawora
     
    Loocek, Mar 17, 2009
    #3
  4. In article <gpojuj$77l$-kr.edu.pl>, Loocek <> wrote:

    >A "raw" input stream of data is read by parser. It creates objects in
    >memory, next base on the object - we create a new "raw" stream that is
    >exactly substring of original string. It waste memory and cpu....


    Well, sometimes. Sometimes the DOM is modified after it's read in.
    Even if it isn't, perhaps it needs namespace declarations that were
    not present in that fragment originally. Hanging fragments of the
    original text on to the relevant parts of the DOM just in case it gets
    used is a waste of memory and cpu 99.9% of the time.

    Making your case slow and the usual case fast is probably better
    overall.

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.
     
    Richard Tobin, Mar 17, 2009
    #4
  5. Loocek wrote:
    > My XMLs are quite big... [100k]


    ?

    Hermann
     
    Hermann Peifer, Mar 18, 2009
    #5
  6. Loocek

    Albert Guest

    Loocek a écrit :
    > Hi,
    >
    > I need to find and extract inner xml and save as String.
    > I cannot find that functionality in any [DOM,SAX,STAX] xml parser in
    > java...
    > I was able to do it in DOM by serializing Node - but is stupid solution....
    > Would you give me any suggestion [or part of example] how to do it?
    > My XMLs are quite big... [100k]
    >
    > Thanks for any help
    >
    > Regards
    > Pawel Z


    You can do it in SAX by enabling a flag when the "inner" XML start, and
    then keep reconstructing the XML from XML events (start/endElement() and
    characters() mainly) until the end of the inner XML is reached.

    HTH
     
    Albert, Mar 19, 2009
    #6
  7. Loocek

    anon_anon

    Joined:
    Nov 28, 2009
    Messages:
    1
    Use VTD-XML

    With VTD-XML you can use getElementFragment() to extract inner XML in one function call, in a byte array, it is the most elegant solution
     
    anon_anon, Nov 28, 2009
    #7
    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. Carlo v. Dango
    Replies:
    14
    Views:
    1,087
    Alex Martelli
    Oct 19, 2003
  2. Pyenos
    Replies:
    2
    Views:
    407
    Pyenos
    Dec 27, 2006
  3. kj

    Help! how to extract inner text?

    kj, Jul 1, 2004, in forum: Javascript
    Replies:
    4
    Views:
    143
  4. Golam Md. Shibly
    Replies:
    0
    Views:
    77
    Golam Md. Shibly
    Mar 1, 2014
  5. Jason Friedman
    Replies:
    0
    Views:
    91
    Jason Friedman
    Mar 8, 2014
Loading...

Share This Page