Re: Validate XML against xsdschema when parsing



Schema validation is not integrated with the DOM parser the way DTD validation is. Like Pablo says, you must create both a parser object and a validator object. If you use libxml++ 2.38.0 or later, use XsdValidator. SchemaValidator is deprecated. There is an example in libxml++: https://git.gnome.org/browse/libxml++/tree/examples/schemavalidation

Kjell

Den 2016-02-06 kl. 00:38, skrev Pablo Madoery:
first You have to have an schema.xsd file.
then I think you have to do something like this:

                string schema = "schema.xsd"
SchemaValidator validator(schema);

DomParser parser;
parser.set_throw_messages(true);

               string xml = "file.xml"

parser.parse_file(xml);

validator.validate(parser.get_document());

                xmlpp::Node* rootNode = parser.get_document()->get_root_node();

                ....

and continue parsing.

I haven't test it

regards


On Fri, Feb 5, 2016 at 7:41 PM, Lingxiao Jia <Lingxiao Jia arm com> wrote:

Hello all,

 

We have a project that wants to use libxml++ to parse and validate xml files. Originally we use DTD to validate, but recently we want to switch to XML Schema.

However, I cannot find a way to do validation with parsing just as we did with DTD by calling set_validate().

Is there someone who knows if it is possible to do it simply, or I have to create a XsdValidator object separately to validate the XML file?

 

Best regards,

Lingxiao

 

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

If any information in this message is really confidential, you should not have sent it to a mailing list, where anyone can read it.


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