import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param target
* @return
*/
boolean equivalentXml(Object target)
{
boolean result = false;
if (target instanceof XML)
{
XML otherXml = (XML) target;
// Compare with toString() if either side is text node or attribute
// otherwise compare as XML
XmlCursor.TokenType thisTT = tokenType();
XmlCursor.TokenType otherTT = otherXml.tokenType();
if (thisTT == XmlCursor.TokenType.ATTR || otherTT == XmlCursor.TokenType.ATTR ||
thisTT == XmlCursor.TokenType.TEXT || otherTT == XmlCursor.TokenType.TEXT)
{
result = toString().equals(otherXml.toString());
}
else
{
XmlCursor cursOne = newCursor();
XmlCursor cursTwo = otherXml.newCursor();
result = LogicalEquality.nodesEqual(cursOne, cursTwo);
cursOne.dispose();
cursTwo.dispose();
// Old way of comparing by string.
// boolean orgPrettyPrinting = prototype.prettyPrinting;
// prototype.prettyPrinting = true;
// result = toXMLString(0).equals(otherXml.toXMLString(0));
// prototype.prettyPrinting = orgPrettyPrinting;
}
}
else if (target instanceof XMLList)
{
XMLList otherList = (XMLList) target;
if (otherList.length() == 1)
{
result = equivalentXml(otherList.getXmlFromAnnotation(0));
}
}
else if (hasSimpleContent())
{
String otherStr = ScriptRuntime.toString(target);
result = toString().equals(otherStr);
}
return result;
}