SAXParser inner XML of entity

Discussion in 'Java' started by Mize-ze, Jul 12, 2007.

  1. Mize-ze

    Mize-ze Guest

    Hi,
    Using a SAXParser, how can I get the "inner XML" of entity?

    for example:

    Let's say this is my XML:

    <foo>
    <bar att="">some text </bar>
    </foo>

    and I want to get the string "<bar att="">some text </bar>" .

    If I am extending a DefaultHandler I have access to events for start/
    endElement and characters.
    but what about just getting the inner xml of an entity?

    Thanks
    Mize-ze, Jul 12, 2007
    #1
    1. Advertising

  2. Mize-ze

    Mize-ze Guest

    On Jul 12, 10:29 am, Mize-ze <> wrote:
    > Hi,
    > Using a SAXParser, how can I get the "inner XML" of entity?
    >
    > for example:
    >
    > Let's say this is my XML:
    >
    > <foo>
    > <bar att="">some text </bar>
    > </foo>
    >
    > and I want to get the string "<bar att="">some text </bar>" .
    >
    > If I am extending a DefaultHandler I have access to events for start/
    > endElement and characters.
    > but what about just getting the inner xml of an entity?
    >
    > Thanks


    ?
    Mize-ze, Jul 12, 2007
    #2
    1. Advertising

  3. Mize-ze

    Lew Guest

    Mize-ze wrote:
    > On Jul 12, 10:29 am, Mize-ze <> wrote:
    >> Hi,
    >> Using a SAXParser, how can I get the "inner XML" of entity?
    >>
    >> for example:
    >>
    >> Let's say this is my XML:
    >>
    >> <foo>
    >> <bar att="">some text </bar>
    >> </foo>
    >>
    >> and I want to get the string "<bar att="">some text </bar>" .
    >>
    >> If I am extending a DefaultHandler I have access to events for start/
    >> endElement and characters.
    >> but what about just getting the inner xml of an entity?
    >>
    >> Thanks

    >
    > ?


    First of all, I am not clear why you answered your own first post.

    I am going to guess what you mean by "'inner XML' of entity"; the phrase
    conveys no meaning to me. Do you want to know how to process nested tags?

    When the startElement() method is called, it gives you the tag name (possibly
    with namespace). That tells you which tag you're processing. When I write
    SAX parsers I write a separate parser class for each tag and maintain a holder
    that keeps track of the current parser object. That object maintains a
    reference to the parser for its enclosing tag so I can tell the difference
    between, for example, the "address" tag inside a "person" and one inside an
    "organization".

    That may be too complicated at first, in which case you might use a parser
    class that maintains an internal state machine or other construct for all
    possible tags in the document, then farms out to (private) methods the logic
    for each different tag. You might have a handleFoo() and a handleBar() in
    your class. Your startElement() would call the appropriate method depending
    on the tag argument (localName or qName).

    --
    Lew
    Lew, Jul 12, 2007
    #3
    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. Per Magnus L?vold
    Replies:
    0
    Views:
    2,012
    Per Magnus L?vold
    Nov 16, 2004
  2. Samuel van Laere

    Entity Name or Entity Number?

    Samuel van Laere, Feb 24, 2007, in forum: HTML
    Replies:
    4
    Views:
    1,617
    Jukka K. Korpela
    Feb 24, 2007
  3. -saarland.de
    Replies:
    2
    Views:
    910
    Magnus Henriksson
    Jan 25, 2007
  4. markla
    Replies:
    1
    Views:
    540
    Steven Cheng
    Oct 6, 2008
  5. Norm
    Replies:
    3
    Views:
    2,699
Loading...

Share This Page