[thelist] XML parsing

David.Cantrell at Gunter.AF.mil David.Cantrell at Gunter.AF.mil
Tue Oct 8 08:19:01 CDT 2002


>Option 1 is siblings all as children of the root element.
>Option 2 is infinitely nested siblings. The younger brother nested inside
the
>elder.
>
>Option 2 is more complicated to parse, will take longer and drain more
memory.
>Option 1 is the way xml is intended to be used.

Huh? This doesn't make any sense to me at all. If you are creating
parent-child relationships, why not model them as parent-child elements?

I won't necessarily argue with you about the memory usage issue, but then
that's why we have SAX parsers. :)

My issue here is the assertion that "Option 1 is the way XML is meant to be
used", meaning it shouldn't have nested parent-child relationships. If this
were true then 99.999% of XML applications, including XHTML and SOAP, would
be invalid. I also find it hard to believe the W3C would have spent so much
time giving XML the capability to model these relationships if it weren't
meant to be used this way.

Luckily I have the original e-mail, so let's recap: (I added "root" for
clarity and cleaned it up a bit)

	[Option 1]
	<root>
		<topic id="1" name="joe" />
		<topic id="2" name="joe's kid" parent="1" />  <!-- CHILD of
id=1 -->
	</root>

	[Option 2]
	<root>
		<topic id="1" name="joe">
			<topic id="2" name="joe's kid" />  <!-- CHILD of
id=1 -->
		</topic>
	</root>

The key point to me in option 1 is the use of the "parent" attribute. Using
this states unequivocally that I am modeling a parent-child relationship.
But instead of using the built-in features of the XML DOM (ChildNodes
collection, and the XPath axes "parent", "child", "descendant",
"descendant-or-self", "ancestor", and "ancestor-or-self") I have decided I'm
going to write my own parent-child parser.

Not sure *why* I have to write this capability myself, but I'm told it's
"the way xml is intended to be used." ;P

Just my $.02,
-dave



More information about the thelist mailing list