You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Stottlemyer, Carl" <ca...@lmco.com> on 2004/07/27 23:37:27 UTC
Parsing "aggregate" Xml documents
I have a situation similar to the following (the names have been changed
to make the poster appear as though they work on something fun)
I currently have a SAX parser that can read an xml document:
football_team.xml.
<football_team>
...
</football_team>
I parse the football team document through the an object called
FootballTeamXmlParser. The method is:
FootballTeamXmlParser
public FootballTeam parse(InputSource pSource);
I now have a new document called: football_league.xml that is an
aggregation of several football teams. Note: The file structure of
football_team.xml is embedded in football_league.xml. The file,
football_league.xml does not contain references to external files like
football_team.xml.
<football_league>
<commissioner>Carl Stottlemyer</commissioner>
...
<football_team>Xml structure same as
football_team.xml</football_team>
<football_team>...</football_team>
...
</football_league>
I would like to create a SAX parser, FootballLeagueXmlParser, that
utilizes my FootballTeamXmlParser. I still want my
FootballTeamXmlParser to be capable of parsing standalone documents. I
would like my FootballLeagueXmlParser to call the FootballTeamParser
whenever a <football_team> is encountered. However, I can't find an
easy way to extract all of the content within a <football_team> as an
InputSource so that I can pass it to my FootballTeamParser.
Can anyone offer any recommendations to get the most reuse out of my
FootballTeamXmlParser?
Thank you,
Carl Stottlemyer
Software Engineer
Re: Parsing "aggregate" Xml documents
Posted by Joseph Kesselman <ke...@us.ibm.com>.
XML parsers aren't generally designed to extract sub-documents as such. You
can achieve this result by running a single parse on the complete document
and routing the output in appropriate directions -- eg, by having the
parser feed a SAX processor which fans out the input to other SAX
processors, or by building a single DOM and then calling routines that
process specific subtrees.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org