SAXParser inner XML of entity

M

Mize-ze

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
 
M

Mize-ze

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

?
 
L

Lew

Mize-ze said:

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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top