[xsde-users] Working with porly formed legacy xml
Boris Kolpackov
boris at codesynthesis.com
Fri Nov 7 15:16:03 EST 2008
Hi Eric,
Fitzsimmons, Eric <EFitzsimmons at cantorgaming.com> writes:
> I have some legacy code that has a circular dependency between the
> parsers within the xml. I've seen the file per type information
> and have run the command to generate these classes, but I still
> don't see how it solves this problem.
The file-per-type mode is there to solve a bit different problem,
namely, cyclic dependencies between schema files. What you have
is recursive parsing. That is, you have a parser that can be
called recursively during parsing of its child elements. The
generated code fully supports recursive parsing though you will
need to be careful if your parser implementations have any state.
In this case you may need to use a stack to save the state during
parsing (there is one in libxsde/xsde/cxx/parser/state.hxx that
is used in the parser skeletons).
I gave your schema and XML fragment a quick test using the
automatic sample implementation/test driver generation feature:
$ xsde cxx-parser --generate-print-impl --generate-test-driver \
--root-element object test.xsd
$ g++ -I.../libxsde -o driver *.cxx .../libxsde/xsde/libxsde.a
$ ./driver test.xml
When I tried to run the test driver on your XML I got a couple
of errors:
test.xml:10:42: invalid NMTOKEN value
test.xml:12:8: mismatched tag
test.xml:15:2: mismatched tag
The 'some address' value is not a valid NMTOKEN plus there
were a coupe of closing tags missing. After fixing those the
sample XML looks like so:
<object name="Person" id="1">
<field type="name" value="SomeName" />
<field type="age" value="35" />
<field type="jobs">
<array>
<object name="Job" id="1">
<field type="firstJob" value="true" />
<field type="Addresses">
<array>
<field value="some-address" />
</array>
</field>
</object>
</array>
</field>
</object>
When I run the test driver on it I get:
$ ./driver test.xml
name: Person
id: 1
type: name
value: SomeName
type: age
value: 35
type: jobs
name: Job
id: 1
type: firstJob
value: true
type: Addresses
value: some-address
Boris
More information about the xsde-users
mailing list