开发者

SAX2 (Xerces-C): How to get the line number of parsed tags?

I parse an XML file in C++ using the SAX2 api of Xerces-C. So I do implement the DefaultHandler interface and its functions

void startElement(
    const   XMLCh* const    uri,
    const   XMLCh* const    localname,
    const   XMLCh* const    qname,
    const   xercesc::Attributes&     attrs
);

and

void endElement(
    const   XMLCh* const    uri,
    const   XMLCh* const    localname,
    const   XMLCh* const    qname
);

When the xml file has a syntax error, the thrown SAXParseException gives me the line number wher开发者_StackOverflow中文版e the error occurred and I can print the error line to the user.

In my application it is possible that the syntax is well formed but the contained data doesn't have much sense. In this case I would also like to print the error line to the user. But I didn't find a way to get the current line number, because the xml is syntactically correct and there is no SAXParseException thrown. Is there a way to get the line number of a tag?


Override the setDocumentLocator() method in your class derived from xercesc::DefaultHandler to get hold of the xercesc::Locator object. You can then call its getLineNumber() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜