|
List Info
Thread: libxml + sax + schema validation
|
|
| libxml + sax + schema validation |

|
2007-02-06 08:33:57 |
Hi,
I need to write a sax xml parser that will
validate the contents against a xml schema file.
Writing a sax parser wasn't to hard, but I have no
clue how to implement the schema validation.
Can anyone help me?
Links to some examples would be great
BR, Jovan
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: libxml + sax + schema validation |

|
2007-02-06 09:31:55 |
On Tue, Feb 06, 2007 at 03:33:57PM +0100, Jovan Kostovski
wrote:
> Hi,
>
> I need to write a sax xml parser that will
> validate the contents against a xml schema file.
>
> Writing a sax parser wasn't to hard, but I have no
> clue how to implement the schema validation.
>
> Can anyone help me?
> Links to some examples would be great
there is an API to push a schemas validation context on
top of
a SAX event, see xmlSchemaValidateStream() use in testSAX()
in xmllint.c
Daniel
--
Red Hat Virtualization group http://redhat.com/v
irtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard redhat.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/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Libxml not catching schema error |
  United States |
2007-02-07 17:18:50 |
Hi,
It seems libxml2 sometimes doesn't catch duplicate elements
(under the
same parent element) when loading a schema. (Please see the
simple
schema at the end).
xmlSchemaParserCtxtPtr parserCtxtPtr =
xmlSchemaNewParserCtxt("./sample.xsd"); -----line
1
xmlSchemaPtr schema = xmlSchemaParse(parserCtxtPtr);
------------>
line 2
Line 1 creates a parser context, and line 2 creates schema
pointer.
For the schema below, there are two "ifid"
elements in "interface_type"
complexType, I expect line 2 reports an error saying
duplicate elements
defined, but instead, line 2 returns fine.
Thanks,
Yong Chen
Sample.xsd:
<?xml version="1.0"?>
<xs:schema xmlns s=&qu
ot;http://www.w3.
org/2001/XMLSchema"
xmlns="http://www.my.com/test&q
uot; targetNamespace="http://www.my.com/test&q
uot;
elementFormDefault="qualified">
<xs:element name="show"
type="show_type"/>
<xs:complexType name="show_type">
<xs:sequence>
<xs:element name="interface"
minOccurs="1"
type="interface_type"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="interface_type">
<xs:sequence>
<xs:element name="ifid"
minOccurs="1" type="xs:string"/>
<xs:element name="ifid"
minOccurs="1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: Libxml not catching schema error |
  United States |
2007-02-07 17:30:15 |
One more info: it also doesn't catch duplicates in following
(slightly
modified) sample file. Basically I inserted
<xs:choice> as the parent of
those two "ifid" elements.
Thanks,
Yong Chen
<?xml version="1.0"?>
<xs:schema xmlns s=&qu
ot;http://www.w3.
org/2001/XMLSchema"
xmlns="http://www.my.com/test&q
uot;
targetNamespace="http://www.my.com/test&q
uot;
elementFormDefault="qualified">
<xs:element name="show"
type="show_type"/>
<xs:complexType name="show_type">
<xs:sequence>
<xs:element name="interface"
minOccurs="1"
type="interface_type"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="interface_type">
<xs:sequence>
<xs:choice>
<xs:element name="ifid"
minOccurs="1" type="xs:string"/>
<xs:element name="ifid"
minOccurs="1" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:schema>
> -----Original Message-----
> From: xml-bounces gnome.org [mailto ml-bo
unces gnome.org] On
> Behalf Of Yong Chen (yongche)
> Sent: Wednesday, February 07, 2007 3:19 PM
> To: xml gnome.org
> Subject: [xml] Libxml not catching schema error
>
> Hi,
>
> It seems libxml2 sometimes doesn't catch duplicate
elements
> (under the same parent element) when loading a schema.
> (Please see the simple schema at the end).
>
> xmlSchemaParserCtxtPtr parserCtxtPtr =
> xmlSchemaNewParserCtxt("./sample.xsd");
-----line 1
> xmlSchemaPtr schema = xmlSchemaParse(parserCtxtPtr);
> ------------>
> line 2
>
> Line 1 creates a parser context, and line 2 creates
schema pointer.
>
> For the schema below, there are two "ifid"
elements in
> "interface_type"
> complexType, I expect line 2 reports an error saying
> duplicate elements defined, but instead, line 2 returns
fine.
>
> Thanks,
> Yong Chen
>
>
> Sample.xsd:
>
> <?xml version="1.0"?>
> <xs:schema xmlns s=&qu
ot;http://www.w3.
org/2001/XMLSchema"
> xmlns="http://www.my.com/test&q
uot;
> targetNamespace="http://www.my.com/test&q
uot;
> elementFormDefault="qualified">
> <xs:element name="show"
type="show_type"/>
> <xs:complexType name="show_type">
> <xs:sequence>
> <xs:element name="interface"
minOccurs="1"
> type="interface_type"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType
name="interface_type">
> <xs:sequence>
> <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
> _______________________________________________
> xml mailing list, project page http://xmlsoft.org/
> xml gnome.org http://mai
l.gnome.org/mailman/listinfo/xml
>
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: Libxml not catching schema error |

|
2007-02-08 13:22:21 |
Hi Yong,
"Yong Chen (yongche)" <chen cisco.com> writes:
> <xs:complexType
name="interface_type">
> <xs:sequence>
> <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
This is valid as long as the two elements with the same name
have
the same type (XML Schema "consistent declaration
rule"). The
fragment above is equivalent to:
<xs:complexType name="interface_type">
<xs:sequence>
<xs:element name="ifid"
minOccurs="2" maxOccurs="2"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis
.com
Open-Source, Cross-Platform C++ XML Data Binding
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: Libxml not catching schema error |

|
2007-02-08 13:27:13 |
Hi Yong,
"Yong Chen (yongche)" <chen cisco.com> writes:
> <xs:complexType
name="interface_type">
> <xs:sequence>
> <xs:choice>
> <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> </xs:choice>
> </xs:sequence>
> </xs:complexType>
This is also valid though does not make much sense (e.g, a
choice
between two equivalent elements). One scenario where
repeating
the same element would me sense is something along these
lines:
<xs:complexType name="interface_type">
<xs:sequence>
<xs:element name="ifid"
type="xs:string"/>
<xs:element name="foo"
type="xs:string"/>
<xs:element name="ifid"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
I.e., you want an element ifid followed by element foo which
in turn
is followed by another element ifid.
hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis
.com
Open-Source, Cross-Platform C++ XML Data Binding
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: Libxml not catching schema error |
  United States |
2007-02-08 15:48:12 |
Hi Boris,
Thanks a lot for the response.
But libxml2 doesn't catch the problem even if I change the
type of the
first "ifid" to "xs:integer". (with or
without "xs:choice" as the parent
of "ifid" elements).
Thanks,
Yong Chen
> -----Original Message-----
> From: xml-bounces gnome.org [mailto ml-bo
unces gnome.org] On
> Behalf Of Boris Kolpackov
> Sent: Thursday, February 08, 2007 11:27 AM
> To: xml gnome.org
> Subject: Re: [xml] Libxml not catching schema error
>
> Hi Yong,
>
> "Yong Chen (yongche)" <chen cisco.com> writes:
>
> > <xs:complexType
name="interface_type">
> > <xs:sequence>
> > <xs:choice>
> > <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> > <xs:element name="ifid"
minOccurs="1" type="xs:string"/>
> > </xs:choice>
> > </xs:sequence>
> > </xs:complexType>
>
> This is also valid though does not make much sense
(e.g, a
> choice between two equivalent elements). One scenario
where
> repeating the same element would me sense is something
along
> these lines:
>
> <xs:complexType name="interface_type">
> <xs:sequence>
> <xs:element name="ifid"
type="xs:string"/>
> <xs:element name="foo"
type="xs:string"/>
> <xs:element name="ifid"
type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
>
> I.e., you want an element ifid followed by element foo
which
> in turn is followed by another element ifid.
>
>
> hth,
> -boris
>
>
> --
> Boris Kolpackov
> Code Synthesis Tools CC
> http://www.codesynthesis
.com
> Open-Source, Cross-Platform C++ XML Data Binding
>
> _______________________________________________
> xml mailing list, project page http://xmlsoft.org/
> xml gnome.org http://mai
l.gnome.org/mailman/listinfo/xml
>
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: Libxml not catching schema error |

|
2007-02-09 01:03:11 |
Hi Yong,
"Yong Chen (yongche)" <chen cisco.com> writes:
> But libxml2 doesn't catch the problem even if I change
the type of the
> first "ifid" to "xs:integer". (with
or without "xs:choice" as the parent
> of "ifid" elements).
This is a bug then. Note also that the XML Schema support in
libxml2 is
not yet complete.
hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis
.com
Open-Source, Cross-Platform C++ XML Data Binding
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Re: Libxml not catching schema error |
  United States |
2007-02-09 15:02:46 |
:-(, I thought the schema implementation was complete!
Thanks,
Yong Chen
> -----Original Message-----
> From: xml-bounces gnome.org [mailto ml-bo
unces gnome.org] On
> Behalf Of Boris Kolpackov
> Sent: Thursday, February 08, 2007 11:03 PM
> To: xml gnome.org
> Subject: Re: [xml] Libxml not catching schema error
>
> Hi Yong,
>
> "Yong Chen (yongche)" <chen cisco.com> writes:
>
> > But libxml2 doesn't catch the problem even if I
change the
> type of the
> > first "ifid" to "xs:integer".
(with or without "xs:choice" as the
> > parent of "ifid" elements).
>
> This is a bug then. Note also that the XML Schema
support in
> libxml2 is not yet complete.
>
> hth,
> -boris
>
>
> --
> Boris Kolpackov
> Code Synthesis Tools CC
> http://www.codesynthesis
.com
> Open-Source, Cross-Platform C++ XML Data Binding
>
> _______________________________________________
> xml mailing list, project page http://xmlsoft.org/
> xml gnome.org http://mai
l.gnome.org/mailman/listinfo/xml
>
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
| Copy properties and namespaces |
  United States |
2007-02-09 21:13:26 |
Hi,
I've a question regarding copying one node's properties and
namespaces.
First, I want to copy all properties of node A to B, is it
correct to do
following?
B->properties=xmlCopyPropList(B,
A->properties)
Then, I also know that node A has several namespaces defined
(such as
xmlns:first="www.first.com"
xmlns:second="www.second.com"), I want to
copy all of them to node B, should I do both of following?
B->ns=xmlCopyNamespaceList(A->ns);
And
B->nsDef=xmlCopyNamespaceList(A->nsDef);
Thanks in advance for your help,
Yong Chen
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
|
|
[1-10]
|
|