[xml] problems validating a XML doc
- From: "MDC A." <comymar yahoo es>
- To: xml gnome org
- Subject: [xml] problems validating a XML doc
- Date: Wed, 27 Feb 2002 16:01:32 +0100 (CET)
hi,
I have started to use the libxml2.2.4.15 on Solaris
2.8, and I have a problem when I try to validate a
memory buffer against a DTD that I have parsed before.
My DTD is like this:
<?xml encoding="ISO-8859-1"?>
<!ELEMENT REQ (CLIENT,LIR)>
<!ATTLIST REQ ver CDATA #FIXED "3.00">
<!ELEMENT CLIENT (ID, PWD)>
<!ELEMENT ID (#PCDATA)>
<!ELEMENT PWD (#PCDATA)>
<!ELEMENT LIR (MSIDS, QoS?, GEO_INFO?)>
<!ELEMENT MSIDS ((MSID | MSID_RANGE)+, MSID_TYPE?)>
<!ELEMENT MSID (#PCDATA)>
<!ELEMENT MSID_RANGE (START_MSID, STOP_MSID)>
<!ELEMENT START_MSID (#PCDATA)>
<!ELEMENT STOP_MSID (#PCDATA)>
<!ELEMENT MSID_TYPE (#PCDATA)>
<!ELEMENT GEO_INFO (COORD_SYS?, DATUM?, FORMAT?)>
<!ELEMENT COORD_SYS (#PCDATA)>
<!ELEMENT DATUM (#PCDATA)>
<!ELEMENT FORMAT (#PCDATA)>
<!ELEMENT QoS (MAX_DEL?)>
<!ELEMENT MAX_DEL (#PCDATA)>
and the XML doc I try to validate is that one:
<?xml version = \"1.0\" encoding = \"ISO-8859-1\"
standalone = \"no\"?>\n\
<!DOCTYPE REQ SYSTEM \"prueba.dtd\">\n\
<REQ ver=\"3.00\">\n\
<CLIENT>\n\
<ID> antonio</ID>\n\
<PWD> antonio</PWD>\n\
</CLIENT>\n\
<LIR>\n\
<MSIDS>\n\
<MSID> 3412345678</MSID>\n\
<MSID_RANGE>\n\
<START_MSID> 34555555</START_MSID>\n\
<STOP_MSID> 34666666</STOP_MSID>\n\
</MSID_RANGE>\n\
<MSID_TYPE> MSISDN</MSID_TYPE>\n\
</MSIDS>\n\
<GEO_INFO>\n\
<COORD_SYS> LL</COORD_SYS>\n\
<DATUM> WGS-84</DATUM>\n\
<FORMAT> IDMS0</FORMAT>\n\
</GEO_INFO>\n\
</LIR>\n\
</REQ>
Accord to my DTD the Element MSIDS of my XML doc is
not right, because it only can have one children
between MSID and MSID_RANGE (
<!ELEMENT MSIDS ((MSID | MSID_RANGE)+, MSID_TYPE?)> )
and it has both. But when I try to parse it with
xmlValidateDTD() I obtain a returned value of 1 (so,
it validates it).
If I change the MSIDS Element in the DTD definition
and
I define it like
<!ELEMENT MSIDS ((MSID | MSID_RANGE), MSID_TYPE?)>
and I try to validate the same XML doc,
it works ok, and I obtain a returned value of 0.
Is the first definition of my DTD possible or I can't
define the element MSIDS like
<!ELEMENT MSIDS ((MSID | MSID_RANGE)+, MSID_TYPE?)>?
Is it a bug of the librarie?
Am I making something wrong?
Can I validate it by another way? I need a quickly
validation so it isn't efficient for me to use
xmlValidateDocument() (I have try to use this function
but it doesn't work right with a DTD definition like
that one:
<!ELEMENT MSIDS ((MSID | MSID_RANGE)+, MSID_TYPE?)>)
I implement the following steps in my code:
xmlDocPtr arbol = NULL;
arbol =
xmlParseMemory(XMLInMemBuf,strlen(XMLInMemBuf));
if (arbol == NULL)
{
printf("ERROR\n");
xmlFreeDoc(arbol);
xmlCleanupParser();
exit(-1);
}
xmlValidCtxtPtr ptrCtxt = (struct _xmlValidCtxt
*)malloc(sizeof(struct _xmlValidCtxt);
ptrCtxt->error=(xmlValidityErrorFunc)trataError;
ptrCtxt->warning=(xmlValidityWarningFunc)trataWarning;
xmlDtdPtr ptrDTD = NULL;
xmlChar *systemID = BAD_CAST("prueba");
ptrDTD = xmlParseDTD(NULL,systemID);
if (ptrDTD == NULL)
{
printf("ERROR\n");
xmlFreeDoc(arbol);
xmlCleanupParser();
exit(-1);
}
resultado = xmlValidateDtd(ptrCtxt, arbol, ptrDTD);
if (resultado == 0)
{
printf("ERROR\n");
xmlFreeDoc(arbol);
xmlFreeDtd(ptrDTD);
xmlCleanupParser();
exit(-1);
}
thanks a lot for your help and time.
_______________________________________________________________
Do You Yahoo!?
Yahoo! Messenger
Comunicación instantánea gratis con tu gente.
http://messenger.yahoo.es
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]