XML traversal in levelorder
- From: "C. Rühl" <chris@xxxxxxxxxx>
- Date: Wed, 5 Dec 2007 05:51:03 -0800 (PST)
Hi,
I would like to traverse a XML document in levelorder. My next steps
depend on different nodes and their levels.
What I did by now was to set up a XmlStreamEventReader to easily
choose the next steps for each node and node-type:
m_in = new FileInputStream(file);
m_factory = XMLInputFactory.newInstance();
m_parser =
m_factory.createXMLEventReader(m_in);
// parse events
while(this.m_parser.hasNext())
{
XMLEvent event = m_parser.nextEvent();
switch(event.getEventType())
{
case
XMLStreamConstants.START_DOCUMENT:
break;
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
// common mib files
if(startElement.getName().toString()=="Common")
newCommonInstance(startElement);
....
The XmlStreamEventReader traverses the XML file in preorder.
And because of my XML file only consists of nodes with attributes (so
there's no node-value only attributes an their values), working with a
DOM is pretty strange. As soon as I walk through the nodes my root has
i.e. 5 instead of actually 2 children:
root
#text
node1
#text
node2
#text
How do I get rid of the "#text"-blanks or what should I do to
correctly traverse in levelorder?
.
- Follow-Ups:
- Re: XML traversal in levelorder
- From: C. Rühl
- Re: XML traversal in levelorder
- Prev by Date: Re: help with return statement
- Next by Date: Re: XStream versus XMLEncoder
- Previous by thread: XStream versus XMLEncoder
- Next by thread: Re: XML traversal in levelorder
- Index(es):
Relevant Pages
|