[xml] default values from schema

Hello to the list,

I know I have a FAQ but I cannot manage it by myself :(

I have a xsd schema and need to validate *and* parse a xml file making use
of the default values from the schema. 

In the end I need it in C++ but I guess it helps to have it first in Python?!

My minimalistic example is based on http://www.w3schools.com/xml/schema_howto.asp
extended by attributes, one with default -> see attachment.

Validating works nicely :) Any error in the xml is detected or ret=0 if the file is ok.

doc = libxml2.parseFile(„node.xml“)
s = libxml2.schemaNewParserCtxt(„node.xsd“)
sp = s.schemaParse()
ct = sp.schemaNewValidCtxt()  
ret = ct.schemaValidateDoc(doc)

But I have no idea on how to get the populated data from this (only from doc).

Then I tried to extend the reader example:

def streamFile(filename):
    reader = libxml2.newTextReaderFilename(filename)
    s = libxml2.schemaNewParserCtxt(‚node.xsd‘)
    sp = s.schemaParse()
    ct = sp.schemaNewValidCtxt()
    ct.SchemaValidateCtxt(reader, libxml2.XML_SCHEMA_VAL_VC_I_CREATE)
    reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS, 1)
    ret = reader.Read()
    while ret == 1:
        ret = reader.Read()

However, with the reader api the root element is not recognized and the default attribute is not set:

Element ‚{http://www.w3schools.com}note‘: No matching global declaration available for the validation root.

As the schema is validated properly in the first code I believe the schema is ok.

So my questions are:
* Which api shall I use to make use of the default values?
* Shall I try in C instead of Python?
* Is there a link which helps me? I spent two days googling without success :(

Thanks a lot!


Attachment: note.xml
Description: application/xml

Attachment: note.xsd
Description: Binary data

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