xerces-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 4pzbro...@sneakemail.com
Subject Re: Validating XML document without namespace
Date Tue, 16 Jan 2007 13:24:28 GMT
Well, I recently had quite similar problem: In short I wanted to 
validate an XML document (an actual XML Schema definition; .xsd) against 
the schema for XML Schema (weird, I know). However, Xerces didn't really 
like that, because of the way schema support is implemented.

I tried validating them against the XML Schema DTD; however, for this to 
work you need to have a <!DOCTYPE> at the start of every .xsd file, 
which wasn't possible.
So what I did was that I created an InputSource that wraps another 
InputSource, analyzing it's content first and then rewriting a cached 
version of that stream in memory, so that for every xmlns=.. there would 
be a <!DOCTYPE> statement before the root element. Xerces, using my 
InputSource, would only see the cached and rewritten version.

So how does this help you? If your input files don't have an xmlns=".." 
attribute on your root element, you could simply add this in in-memory 
and then give that cached and edited version of the input stream to Xerces.

Worked for me in the end; took me a day to write though.

Cheers,

Uwe

Boris Kolpackov boris-at-codesynthesis.com |xerces-c-users mailing list| 
schrieb:
> Hi Edward,
>
> Edward Rozendal <rozendal@hitt.nl> writes:
>
>   
>> I have an application with Xerces 2.4.0 that parses XML using SAX2. My
>> client has supplied me with XML schema's that include namespaces. When I
>> create an XML file with XMLSpy it will look like:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!-- edited with XMLSpy v2006 sp2 U (http://www.altova.com) -->
>> <tns:keepalive xmlns:tns="http://www.example.eu/common/name/v1-0"/>
>>
>> The application does accept and validate this XML file. However I have been
>> asked if it is also possible to accept and validate XML files that look like
>> this:
>>
>> <keepalive/>
>>     
>
> I am pretty sure this is not possible. Element namespace is part of the
> element id (just like name). The best you can do is this:
>
> <keepalive xmlns="http://www.example.eu/common/name/v1-0"/>
>
>
> hth,
> -boris
>
>
>   


Mime
View raw message