You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Edward Rozendal <ro...@hitt.nl> on 2007/01/15 20:59:40 UTC

Validating XML document without namespace

Hi,

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/>

Is it possible to validate XML files without namespaces (by setting SAX2
features, Xerces properties, or otherwise) without changing the XML schema's
that do require namespaces? It is not necessary that the application accepts
XML files with and without namespaces at the same time. The namespace is
available in the application through a parameter.

Thank,
Edward

-- 
View this message in context: http://www.nabble.com/Validating-XML-document-without-namespace-tf3016870.html#a8378172
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Validating XML document without namespace

Posted by 4p...@sneakemail.com.
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 <ro...@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
>
>
>   


Re: Validating XML document without namespace

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Edward,

Edward Rozendal <ro...@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


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding