[xsd-users] Tree Parsing: How to handle schema namespaces missing from XML data

Boris Kolpackov boris at codesynthesis.com
Sun Mar 30 16:03:41 EDT 2008


Hi Henry,

Bruce, Henry <henry.bruce at intel.com> writes:

> I am trying to parse XML data from a web service. The data is described
> by a schema that uses namespaces, but they are not present in the web
> service response.
>
> Now I am seeking to do the equivalent with the tree mapping code
> generated by the CodeSynthesis.

This is actually quite tricky unless you can change your schema to
remove tragetNamespace so that XML that you get corresponds to the
schema and, in turn, the generated code.

If you cannot change your schema then there are a few ways to work
around this but they depend on a few things:

First, can you tell us whether, according to your schema, only the
root element is namespace-qualified or if there are inner namespace-
qualified elements and/or attributes. In other words, whether your
XML document should look like this:

<p:root xmlns:p="http://www.example.com/example">

  <p:inner> ... </p:inner>

<p:root>

or like this:

<p:root xmlns:p="http://www.example.com/example">

  <inner> ... </inner>

<p:root>

This is normally determined by the elementFormDefault attribute in
your schema (if it is not present then by default local elements
are unqualified).

Second, it would be helpful to know if you plan to have XML Schema
validation in Xerces-C++ enabled during parsing (it is enabled by
default). Some work-arounds may not be possible if validation is
enabled.

Boris




More information about the xsd-users mailing list