On Wed, Jun 10, 2009 at 3:14 PM, Dale Worley<[email protected]> wrote:
> On Wed, 2009-06-10 at 14:24 -0500, Kelly Beard wrote:
>> Doesn't anyone here do schema validation/parsing with DOM? I am
>> really trying to find *something* helpful on the net but am shooting
>> blanks here.
>
> The sipXecs project uses validation. The program that implements it is
> accessible at
> http://sipxecs.sipfoundry.org/rep/sipXecs/main/sipXcommserverLib/src/xsdvalid/xsdvalid.cpp
>
> The interesting part of the code starts around line 370.
>
> Dale
>
>
>
>
Ok, I feel like I'm getting somewhere with this except I'm getting
errors with any xml file on the root node. As a simple test I'm using
a sample XSD and two versions of XML from w3schools.com. I'm guessing
that it's the loadGrammar() parameter but I'm not sure. I had to plug
in a '1' instead of Grammar::SchemaGrammarType because the compiler
kept complaining about being an incomplete class. I dont seem to be
getting any error about the XSD itself so I'm not sure.
parser->loadGrammar("/home/kbeard/fly.xsd", 1, true)
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/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>
-----------------------------------------------------
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
------------------------------------------------------
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
--
Kelly Beard