Dear guys, first sorry for my english, and second, the problem. I have a plain XML in a memory buffer as: <E1> </E1> Parsed in a xmlDocPtr without problems.In the other hand I have a XSD file to validate the XML buffer and my xmlSchemaValidCtxtPtr prepared for that XSD file.
The XSD defines a namespace not present in my plain XML and parsed x_doc (xmlDocPtr type variable).
When I run (with error checks omited and tested all these lines executes perfectly):
xmlDocPtr x_doc = xmlReadDoc(
BAD_CAST my_buffer_xml_ptr,
0, // Uri
my_encoding, // Encode
0 // Opciones
);
xmlSchemaParserCtxtPtr x_sh_parser_ctxt = xmlSchemaNewParserCtxt(
BAD_CAST "my path to the XSD file"
);
xmlSchemaPtr x_sh = xmlSchemaParse( x_sh_parser_ctxt );
xmlSchemaValidCtxtPtr x_sh_ctxt = xmlSchemaNewValidCtxt( x_sh );
I have in x_sh_ctxt my validation context and in x_doc my tree.
And, the real problem, the next line is:
int res = xmlSchemaValidateDoc(x_sh_ctxt, x_doc);
After this line, the validation works, but it says to me that a NS is
required. I tried this (before the xmlSchemaValidateDoc() call):
xmlNsPtr x_ns = 0;
xmlNsPtr x_ns2 = 0;
int kk;
xmlNodePtr x_raiz = xmlDocGetRootElement( x_doc );
x_ns = xmlNewNs( x_raiz, BAD_CAST "urn:hl7-org:v2xml", BAD_CAST "" );
if( x_ns ) {
xmlSetNs( x_raiz, x_ns );
}
x_ns2 = xmlNewNs( x_raiz, BAD_CAST "urn:hl7-org:v2xml", BAD_CAST "n" );
if( x_ns2 ) {
xmlSetNs( x_raiz, x_ns2 );
}
kk = xmlReconciliateNs( x_doc, x_raiz );
But now, appears only the root element has a namespace assigned and the
validation fails in first root element child, because it not found the
namespace.
The libxml2 library is not the last version, but before I upgrade the version I want to know if I must use a function as:
void setElementNS(xmlNode * a_node,xmlNsPtr nameSpace)
{
xmlNode *cur_node = NULL;
for (cur_node = a_node; cur_node; cur_node =
cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
cur_node->ns=nameSpace;
}
setElementNS(cur_node->children,nameSpace);
}
}
to assign "manually" the namespace to ALL elements, or there are an API
to do this task.
Any idea about this problem?
Thanks
--
Samuel Díaz García
Director Gerente
ArcosCom Wireless, S.L.L.
CIF: B11828068
c/ Romero Gago, 19
Arcos de la Frontera
11630 - Cadiz
http://www.arcoscom.com
mailto:samueldg arcoscom com
msn: samueldg arcoscom com
Móvil: 651 93 72 48
Tlfn.: 956 70 13 15
Fax: 956 70 34 83
Attachment:
samueldg.vcf
Description: Vcard