Subject: Element.HasChildElements returns true if element has text node but no elements
Hi Alexander,
There is a bug in Element.HasChildElements will return true if an element only contains a text node:
public bool HasChildElements
{
get
{
if (this.ChildNodes.Count > 0)
{
return true;
}
else
{
return false;
}
}
}
Here is a fix:
get
{
foreach (Node node in this.ChildNodes)
if (node.NodeType == NodeType.Element)
return true;
return false;
}
It is causing a NullReferenceException in MethodResponse for certain IQ packets:
if (value.HasChildElements)
{
Element next = value.FirstChild;
if (next.TagName == "string")
Here is a snippet of an IQ packet. Note the space in the value element:
<methodResponse><params><param><value><struct><member><name>error_string</name><value> </value>…
-Ed
There is a bug in Element.HasChildElements will return true if an element only contains a text node:
public bool HasChildElements
{
get
{
if (this.ChildNodes.Count > 0)
{
return true;
}
else
{
return false;
}
}
}
Here is a fix:
get
{
foreach (Node node in this.ChildNodes)
if (node.NodeType == NodeType.Element)
return true;
return false;
}
It is causing a NullReferenceException in MethodResponse for certain IQ packets:
if (value.HasChildElements)
{
Element next = value.FirstChild;
if (next.TagName == "string")
Here is a snippet of an IQ packet. Note the space in the value element:
<methodResponse><params><param><value><struct><member><name>error_string</name><value> </value>…
-Ed
edmacdonald
Show profile
Link to this post
