Hi Gareth,

Your explanation makes sense. And I initially tried to get the parent of the DOMText node that was returned, figuring that it would be the DOMElement that I was looking for. But for some reason, the parent was the wrong DOMElement. It was one level higher than I expected. Here is an example of what I am using:

<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/>
 </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>



Obviously, foo3 is invalid since it isn't even in the schema. In this case it returns me a DOMText node. When I get the parent of that DOMText node, it returns me a DOMElement that represents foo1, where I was expecting it to return the DOMElement that represented foo3.


Here are the errors I get from Xerces 2.3.0:

 Message: Unknown element 'foo3'
 Message: Element 'foo3' is not valid for content model: '(foo2)'

Both of these result is getting a DOMText node from the DOMLocator, and the parent of the DOMText node is the DOMElement foo1.

Is there a way to get the foo3 DOMElement when I get these errors for foo3?

thanks
Larry Rosenzweig



Gareth Reakes wrote:

Hi,

On Mon, 22 Sep 2003, Larry Rosenzweig wrote:



Hello,

I am having a problem with Xerces C++ 2.3.0 where I am getting back a DOMText node from
DOMLocator::getErrorNode(), instead of a DOMElement that I was expecting. I need to store all of the
DOMElement nodes that generate errors when parsing (using a DOMBuilder), so I can refer to them later
in my application. I am setting up my own error handler, which catches all of the errors as I
expected, but then when I call getErrorNode() from the DOMLocator object that I get from the DOMError
object passed into handleError(), it always returns a DOMTEXT node instead of a DOMElement node.




The spec says to return a DOMNode. There is not to much more information
about what should be returned apart from that. For example, if your
invalid element was caused due to the content of the element not matching
the pattern from the datatype, should the text node be returned or the
element node? We may well need to decide on that behaviour. If you do have
the text node you can always get its parent which, if it was the content
of an element, would be that element.

Take a quick look at the test data below:

<base xmlns="http://theborg.org"; xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation="http://theborg.org test.xsd"> <foo1 />
<foo2 >sdas</foo2>
</base>


<xs:element name="base"  >
 <xs:complexType >
   <xs:sequence >
      <xs:element name="foo1" type="xs:integer" />
      <xs:element name="foo2" type="xs:integer"/>
   </xs:sequence>
 </xs:complexType>
</xs:element>



The foo elements are obviously invalid. In the first the DOMElement itself is returned as it is the node available that is invalid. In the second example the DOMText is returned as it has failed validation. I agree that this behaviour may seem a touch unintuitive. Maybe we should think about a consistent policy, or at least thoroughly document the problem.


Gareth






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



Reply via email to