
October 17th, 2004, 02:00 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Bavaria, Germany
Posts: 140
Time spent in forums: 3 h 40 m 41 sec
Reputation Power: 6
|
|
I don't think there's something built-in as you want it, but it's not that hard (if I understand you right):
Code:
string GetFullyQualifiedXPath(Element ele) {
string fullPath = "";
Element current = ele;
do {
strung currentPath += "*[local-name() = '" + current.LocalName + "' && namespace-uri() = '" + current.NamespaceUri + "'";
foreach (Attribute attr in ele.Attributes) {
currentPath += " && @" + attr.Name + " = '" + attr.Value + "'";
}
currentPath += "]";
fullPath = currentPath + "/" + fullPath;
current = current.ParentNode;
} while (current != null);
return fullPath;
}
Above code won't compile in java, it's just some pseudo code. It will generate a full qualified x-path to any element in your document.
Example:
Code:
<Document>
<Root>
<Child Key1="Value" />
</Root>
</Document>
For example, a call of GetFullyQualifiedXPath for Node "Child" will return:
/*[local-name() = 'Document' && namespace-uri() = '']/*[local-name() = 'Root' && namespace-uri() = '']/*[local-name() = 'Child' && namespace-uri() = '' && @Key1 = 'Value']
|