0

Like in XML DOM, childNodes Property is there what is the equivalent in SAX?

I want to know the number of elements for the traversal, like in DOM, we can do,

for (i=0; i<node.getChildNodes().length();i++)
{
   //Traversal code
}

Similarly, what can i use in SAX?

attributes.getlength(); -> This does not solve.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

The length of an array isn't a function, it's a property, and properties usually don't have brackets (). var subnodes = node.getChildNodes().length // .length return the number of elements inside a array.

machinateur
  • 502
  • 5
  • 10
  • I understand your point which is very correct. My question is basically to know the substitute of getChildNodes() like in DOM , in SAX. – user3491492 Apr 10 '14 at 19:47
0

There is no equivalent as SAX is a completely different approach to parsing XML.

In DOM, the entire XML structure is loaded into an in-memory hierarchical data structure, which has traversal methods as you describe.

In SAX, the only data structures held in memory are those you build within an implementation of the ContentHandler interface. You can, as you parse the children of a specific node, hold onto data in a form that can later be traversed similarly, but there's nothing supplied by SAX.

Don Roby
  • 40,677
  • 6
  • 91
  • 113