[xsde-users] Re: Why xml_schema::schema exception is thrown when
the xml document is not well formed
Boris Kolpackov
boris at codesynthesis.com
Mon Oct 29 06:06:25 EDT 2007
Hi Bin,
Jiang, Bin (Bin) <binjiang at alcatel-lucent.com> writes:
> I found in some cases, xml_schema::schema will be thrown when the
> xml document is not well-formed. Take the example library in the
> xsde release 1.1.0 as an example:
>
> <lib:catalog xmlns:lib="http://www.codesynthesis.com/library"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.codesynthesis.com/library library.xsd">
>
> book id="MM" available="false" >
> <isbn>0679760806</isbn>
> <title>The Master and Margarita</title>
> <genre>fiction1</genre>
> ...
> </lib:catalog>
Actually, this XML is perfectly well-formed. By removing '<' from
the book tag, you made it to appear as just a text fragment. Note
that you don't have to escape '>' in the element content.
> If I remove the "<" of book, the parser would say:
> schema error: line[15] column[34] unexpected characters encountered
Which is correct. The catalog type specifies that its content should
be a sequence of book elements. As a result, when parser encounters
text, it reports it as a validation error.
I guess this example shows how far a well-formed XML can be from what
an application expects and why it is generally a good idea to validate
the documents against the vocabulary schema :-).
Boris
More information about the xsde-users
mailing list