Hi, Kai-Uwe.

I assume you use the SAX parser.

If the position (speak location path) to the offending node is sufficient for you,
you might build that on your own, without modifying Xerces.

A location path looks like this:
/rootnode/element[1]/subelement[4]/@attribute

You start with an empty path string.
On each startElement() call, add the name of the element found to the path.
You should also count the number of invocations in case you have several elements with 
the same name on the same level. This may be tricky as you need to keep some sort of 
stack.
On each startAttribute(), start...() modify the path accordingly.
On each endElement remove something from the path, do so accordingly for other 
end...() calls.

Now if an error occurs you can give the logical position of the node that is currently 
processed.

Hiran

> -----Original Message-----
> From: Kai-Uwe Schmidt [mailto:[EMAIL PROTECTED]
> Sent: Monday, March 15, 2004 3:23 PM
> To: [EMAIL PROTECTED]
> Subject: RE: schema validation
> 
> 
> In my case getColumnNumber returns always the bytes of the 
> "node" in my xml-File, not the position where the error 
> occurs. I also use 2_4_0 with vc++ 6.0. ATM i dont see a way 
> to get the position where the error occurs except to "patch" 
> the xerces src :/.
> 
> I used the following code:
> 
> <snip>
>       bool bOK = true;
>       SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
>     parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
>     parser->setFeature(XMLUni::fgXercesDynamic, false);
>     parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
>       parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
>     parser->setFeature(XMLUni::fgXercesSchema, true);
>       parser->setFeature(XMLUni::fgXercesCalculateSrcOfs, true);
>        
> 
>     int errorCount = 0;
>     try
>     {
>         SAX2PrintHandlers handler("LATIN1", 
> XMLFormatter::UnRep_CharRef, false);
>         parser->setContentHandler(&handler);
>         parser->setErrorHandler(&handler);
>         parser->parse(csXmlFile.GetBuffer(0));
>         errorCount = parser->getErrorCount();
>               if (errorCount > 0) {
>                       AfxMessageBox(handler.GetFirstError());
>                       int i=0;
>                       while (++i < errorCount)
>                               AfxMessageBox(handler.GetNextError());
>               }
>     }
> <snap>
> 
> and
> 
> <snip>
> void SAX2PrintHandlers::error(const SAXParseException& e)
> {
>       vReallocErrorList();
>       StrX    poSX = StrX(e.getMessage());
>       char *z = XMLString::transcode(e.getSystemId());
>       ppszErrorList[lErrorItems++] = 
> szFormatMessage(e.getLineNumber(), poSX.Transcode(), 
> e.getColumnNumber());
> }
> 
> 
> <snap>
> 
> 
> 
> 
> 
> 
> 
> Am Mo 15.03.2004 15:02, [EMAIL PROTECTED] schrieb:
> 
> > Hi, Kai-Uwe.
> > 
> > I only use the DOM parser, but my errorhandler gets 
> notified about parsing and validation problems, and they are 
> reported in form of SAXParseExceptions. Here I can call the 
> getColumnNumber()/getLineNumber() methods to find out what 
> caused the problem.
> > 
> > If in your case these methods deliver nothing I think 
> there's a bug in the implementation....
> > 
> > Hiran
> > 
> > PS: Using Xerces C++ 2.4.0 on VC++ 6....
> > 
> > > -----Original Message-----
> > > From: Kai-Uwe Schmidt [mailto:[EMAIL PROTECTED]
> > > Sent: Monday, March 15, 2004 2:57 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: schema validation
> > > 
> > > 
> > > Can anyone help/comment this ?
> > > 
> > > regards
> > > Kai-Uwe
> > > 
> > > Am Do 11.03.2004 20:36, Kai-Uwe Schmidt <[EMAIL PROTECTED]> schrieb:
> > > 
> > > > Hi folks, 
> > > > 
> > > > i am trying to parse a xml with a schema included. I have 
> > > trouble with the informations i get in my errorhandler. 
> > > > i am missing the attribute name in the case the xml doesnt 
> > > conform to the xsd. 
> > > > 
> > > > The SAXParseException doesnt contain any data about the 
> > > position of the attribute which caused the error. Is this a 
> > > misconfiguration of the parse or a bug in my xml/xsd 
> > > definition ? Or is this feature actually not implemented. I 
> > > have back traced the parser up to 
> > > SchemaValidator::validateAttrValue where i can find the 
> > > attribute name with attDef->getFullName() but it doesnt seem 
> > > that the following methodes transport this information down 
> > > to my error handler (at least not with my actuall parser 
> > > configuration). Cananyone help me out to get the name of the 
> > > misfitting attribute ? 
> > > > 
> > > > 
> > > > Just for the case its a missing feature. 
> > > > 
> > > > The Information can be delivered to the user by modifying 
> > > the resource String table ID 16430 like this: 
> > > > Datatype error: Type:{0}, Attribute: {2}, Message:{1}. 
> > > > and upgrading: 
> > > > emitError (XMLValid::DatatypeError, idve.getType(), 
> > > idve.getMessage(),attDef->getFullName()); 
> > > > in SchemaValidator::validateAttrValue. 
> > > > 
> > > > No clue how to make this OS independent (but i hope its not 
> > > such a bad hack). 
> > > > 
> > > > 
> > > > thanks alot 
> > > > Kai-Uwe 
> > > > 
> > > > 
> > > > 
> > > > 
> > > 
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: 
> [EMAIL PROTECTED]
> > > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > 
> > > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to