Sorry it has been a while, I was pulled away on another project at work.
I did as you suggested, subclassing the DOMBuilderImpl class and overriding the virtual error() function call. However, it seems that I am still in the same boat in this function as I was in the DOMErrorHandler callback. I saw in the header file for the AbstractDOMParser class that it stores both the current node (fCurrentNode) and the parent node (fCurrentParent). However, while I can get access to the current node via getCurrentNode(), there is no equivalent function to get the parent. Unless calling getCurrentNode()->getParentNode() would give me the same node as the fCurrentParent member variable?
Since it has been a while since I last responded to you, I quickly recap the problem I am having. Below is an exmaple schema and xml file that shows the problem I am having:
<base xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:/Test/syntax.xsd">
<foo1>
<foo3/>
<foo2 ttt="ttt"/>
</foo1>
</base>
<xsd:element name="base">
<xsd:complexType >
<xsd:sequence >
<xsd:element name="foo1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="foo2"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>Using Xerces-C++ 2.3.0 on WIndows XP Pro. Using Visual C++ 6.0 (service pack 5).
I do receieve the two errors I expect from the above example. One for the invalid element (foo3) and one for the invalid attribute (ttt in foo2). In the first case of the invalid element the getCurrentNode() returns a DOMText node, not foo3 like I expected. If I get the parent node via getCurrentNode()->getParentNode(), I get back foo1. In the second case, getCurrentNode() returns a DOMText node, instead of foo2 like I expected. If I get the parent node via getCurrentNode()->getParentNode(), I get back foo1. In both cases the DOMText node does not have any siblings.
I looked at the area you pointed me to in SGXMLScanner.cpp for the case of an invalid element, but was a little confused on how I could use it to help me. Sorry if I am missing something simple.
I also looked at the XMLValidator class to see if that could help me, but it didn't seem like it could.
Basically I want to store all of the nodes that caused errors according to the schema when the file loads, so that I can then highlight the visual representation of those nodes in my custom editor. I thought just storing the nodes I got back in the DOMErrorHandler or the error() function and going through them after the visual side has been created would work. But I'm not getting the type of nodes I need to make this work.
If you need any more details or code samples, please let me know.
I really appretiate your help. Thank you for your time and effort.
Thanks Larry Rosenzweig
Gareth Reakes wrote:
Hi,
Do you think you could give me a little guidance into how to go about creating this custom error method?
Sure I can.
I have seen some information in the mail archives about setting up an error handler for a XercesDOMParser, but I am using a DOMBuilder to parse my file. I do set my own DOMErrorHandler and override the handleError() call. But that is where I get the DOMLocator that returns the DOMText node that isn't useful to me.
DOMBuilderImpl implements the XMLErrorHandler. Take a look at the error
method. It calls getCurrentNode. I would suggest you implement your own
one of these that does something a bit more complex. It should look at the error code coming in and decide if it should getCurrentNode, or perhaps the parent etc.
This is still going to cause a problem with you child not being in the schema case as you will not know which child to select. If you cannot live with this then I think the easiest way is to add a new error method to XMLErrorHandler that takes a more information. Take a look at SGXMLScanner.cpp:1406. You could call your new error method with info that enable the implementation to select the correct node.
Give us a shout if any of this is not clear.
Gareth
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
