Project

Profile

Help

XPath: Exception processing attribute nodes

Added by Anonymous almost 18 years ago

Legacy ID: #3778180 Legacy Poster: Sudarshan Murthy (smurthy)

When processing the result of evaluating an XPath expression I get the following exception, but only when the expression returns attributes (in C#, .NET): 'Object reference not set to an instance of an object.' Here is the code excerpt. The exception is raised in the last line of the while loop. An example offending XPath expression is: //@ID (ID is indeed an attribute of some of the elements in the input). Another offending expression is: '//Group | //@ID' (somewhat meaningless expression, but should work). Here are some expressions that work just fine: '//Group' and '//concat(@ID, position())' IEnumerator rEnum = selector.GetEnumerator(); while (rEnum.MoveNext()) { XdmItem item = (XdmItem)rEnum.Current; if (item.IsAtomic()) result += (XdmValue)item; else result += ((XdmNode)item).OuterXml; } I can replace the entire loop with either of the following statements, but the exception persists. result += (XdmValue)resultEnum.Current; result += (XdmItem)resultEnum.Current; BTW, is there a way to ask the XdmNode.OuterXml method to exclude the XML header? Thanks, SUN.


Replies (2)

RE: XPath: Exception processing attribute nod - Added by Anonymous almost 18 years ago

Legacy ID: #3779152 Legacy Poster: Michael Kay (mhkay)

Thanks for reporting this. I have registered the bug at https://sourceforge.net/tracker/index.php?func=detail&aid=1506109&group_id=29872&atid=397617 (Unfortunately the fix was too late to make it into 8.7.3). As a circumvention, please do not call the OuterXml property for an attribute node. Access the name and string-value of the node instead. When you use OuterXml you get a standard serialization of the node: if you want detailed control over the serialization, pass the object to a Serializer whose properties you can set. However, on reflection I think it makes more sense for the OMIT_XML_DECLARATION property to be set to "yes" when producing the OuterXml property, so I will change this setting. (As a matter of interest, what would you expect OuterXML to return for an attribute? The patch above generates 'name="value"').

RE: XPath: Exception processing attribute nod - Added by Anonymous almost 18 years ago

Legacy ID: #3779880 Legacy Poster: Sudarshan Murthy (smurthy)

Omitting XML declaration by default makes sense. Also, your proposed output format for attribute nodes is reasonable. (System.Xml formats it as you propose). Thanks for registering the bug. SUN.

    (1-2/2)

    Please register to reply