List Info

Thread: XSchema and libxml




XSchema and libxml
user name
2006-05-23 20:07:54
Hi,

> -----Original Message-----
> From: Hei Chan [mailto:structurechartyahoo.com] 
> 
> Hi Kasimier,
> I have a question about your really old post:
> http://mail.gnome.org/archives/xml/2005-March/msg0004
8.html
> 
> I have tried your example with libxml 2.6.23.  It
> gives me:
> 
> test.xml:6: element note: Schemas validity error :
> Element '{http://www.w3schools.com
}note': No matching
> global declaration available for the validation root.
> The document 'test.xml' is not valid.

I get the following with your scenario:

xmllint --noout --schema http://localhost:8080/
text.xsd test.xml
test.xml validates

> Here is the XML:
> <?xml version="1.0"?>
> 
> <note
> xmlns="http://www.w3schools.com
"
> xmlnssi=&
quot;http://www.
w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://localhost/test.xsd">
> 
> <to>Tove</to>
> <from>Jani</from>
> <heading>Reminder</heading>
> <body>Don't forget me this weekend!</body>
> </note>
> 
> Here is the XSD:
> <?xml version="1.0"?>
> <xs:schema xmlnss=&q
uot;http://www.w3.org/20
01/XMLSchema"
> targetNamespace="http://www.w3schools.com
"
> xmlns="http://www.w3schools.com
"
> elementFormDefault="qualified">
> 
> <xs:element name="note">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element name="to"
type="xs:string"/>
>         <xs:element name="from"
type="xs:string"/>
>         <xs:element name="heading"
type="xs:string"/>
>         <xs:element name="body"
type="xs:string"/>
>       </xs:sequence>
>     </xs:complexType>
> </xs:element>
> 
> </xs:schema>
> 
> If I do the following:
> pCtxt =
> xmlSchemaNewParserCtxt("http://localhost/test.xsd");
> schema = xmlSchemaParse(pCtxt);
> ctxt = xmlSchemaNewValidCtxt(scheam);
> ret = xmlSchemaValidateDoc(ctxt, doc);
> , then it works.
> 
> Is there something wrong with my XML or XSD?  Or is
> the feature(looking up XSD via xsi) turned off?

Right, with xmllint the XSI information is not processed
automatically; you need to specify explicitely both, the
schema and the instance. Actually this is a long-standing
enhancement request, and I currently could also use such a
mechanism in order to plug in Libxml2's XML Schema facility
into my favourite XML editor.

Daniel, would it be OK to add such an option to xmllint?

Relevant bugzilla-entries:
http
://bugzilla.gnome.org/show_bug.cgi?id=157205
http
://bugzilla.gnome.org/show_bug.cgi?id=157973

> In addition to that, is there a way to validate a XML
> against the corresponding schema(specified in the XML)
> automatcially regardless the type of the schema(e.g.
> DTD, XSD, RelaxNG or whatever)?

I don't think so. But you can try to write one.

Regards,

Kasimier
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
XSchema and libxml
user name
2006-05-24 02:06:42
On Tue, May 23, 2006 at 10:07:54PM +0200, Buchcik, Kasimier
wrote:
> Right, with xmllint the XSI information is not
processed
> automatically; you need to specify explicitely both,
the
> schema and the instance. Actually this is a
long-standing
> enhancement request, and I currently could also use
such a
> mechanism in order to plug in Libxml2's XML Schema
facility
> into my favourite XML editor.
> 
> Daniel, would it be OK to add such an option to
xmllint?
> 
> Relevant bugzilla-entries:
> http
://bugzilla.gnome.org/show_bug.cgi?id=157205
> http
://bugzilla.gnome.org/show_bug.cgi?id=157973

  no problem. The only real question is should this be added
as a new
option or override --valid. The problem is that an instance
may have both a DTD 
and an XSI schemas information, so maybe keeping both
separate may be better.

> > In addition to that, is there a way to validate a
XML
> > against the corresponding schema(specified in the
XML)
> > automatcially regardless the type of the
schema(e.g.
> > DTD, XSD, RelaxNG or whatever)?
> 
> I don't think so. But you can try to write one.

  The question is ambiguous. You can't (but this may be
added) specify the
RelaxNG schemas for an instance. There is also schematron,
and of course
the big problem that all these may be used simultaneously,
for example to
validates different namespaces, for example an XHTML
document embedding 
an extra set of informations, you may want to use the XSD
for the XHTML
namespace and something else for the extra foreign islands.
  The people behind RelaxNG are working on such a framework,
but this is
a work in progress, and I'm not sure this can be driven by
informations 
present in the document. After all the whole validation
point is about
checking a document for conformance to *something* if you
start by trusting
the document information itself, well you don't really gain
much in term
of trust, or garantee of purpose for the next processing
steps.

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillardredhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )