Re: [xml] SAX Parsing continues though namespace constaint is violated

On Fri, Oct 17, 2008 at 05:21:37PM +0530, Rabi Narayan Sahoo wrote:


While parsing the following xml file with SAX Parsing I receive all the SAX
Event though it does not satisfy the namespace specification

<?xml version="1.0"?>

<ns1:root xmlns:ns2="uri1" xmlns:ns3="uri2"/>

In the above file ns1 is not declared which violates the Namespace

"The namespace prefix, unless it is xml or xmlns, MUST have been declared in
a namespace declaration attribute in either the start-tag of 

the element where the prefix is used or in an ancestor element"

Libxml simply gives the warning and continues to give SAX events. 

 wei:~/XML -> xmllint --sax tst.xml 
 SAX.error: Namespace prefix ns1 on root is not defined
 SAX.startElementNs(root, ns1, NULL, 2, xmlns:ns2='uri1',
 xmlns:ns3='uri2', 0, 0)
 SAX.endElementNs(root, ns1, NULL)
 wei:~/XML -> xmllint  tst.xml 
 tst.xml:2: namespace error : Namespace prefix ns1 on root is not
 <ns1:root xmlns:ns2="uri1" xmlns:ns3="uri2"/>
 <?xml version="1.0"?>
 <root xmlns:ns2="uri1"
 wei:~/XML ->

 wei:~/XML ->

 Sorry, it's not a warning. You get an error back. A namespace error.
A namespace error is not an XML-1.0 error. You can parse XML-1.0
compliant but not namespace compliant XML documents with libxml2.
If you don't want to parse any further it's your right, and you get
all the informations needed in the error callback for this.

My question is why violation of this constraint is considered as a warning
not as a fatal error?

  You seems to mismatch errors for warnings, also notice the difference
between fatal errors and errors.


Daniel Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]