You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
XML namespaces can be bound to a prefix at any element in a document. They can be bound within an element that uses that namespace prefix. XPath expressions should be able to use the same prefixes. E.g given the document:
I use Document.definePrefix(_ prefix: String, defaultNamespace ns: String) elsewhere in my code to handle a default namespace. Alas, using the same technique here doesn't work, possibly because urn:foo.bar is not bound as a default namespace in the XML:
func testNestedNamespacePrefixWithXPath() {
let docStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><u:BrowseResponse xmlns:u=\"urn:foo.bar\"/></root>"
do {
let document = try Fuzi.XMLDocument(string: docStr)
document.definePrefix("u", defaultNamespace: "urn:foo.bar") // New code
let nodes = document.xpath("/root/u:BrowseResponse")
XCTAssertFalse(nodes.isEmpty)
} catch let error {
print(error)
XCTFail(String(describing:error))
}
}
Seems if the namespace definition is under root element, the query should work. And it doesn't make sense to traverse the whole doc just looking for namespaces.
Description:
XML namespaces can be bound to a prefix at any element in a document. They can be bound within an element that uses that namespace prefix. XPath expressions should be able to use the same prefixes. E.g given the document:
the XPath expression
/root/u:BrowseResponse
should resolve to a nodelist of 1 element.The XPath expression
/root/u:BrowseResponse
resolve to a nodelist of 0 elements and the following is printedIf the document is amended such that the prefix
u:
is bound at the root element the xpath expression evaluates correctly.Environment
How to reproduce:
The following test fails, demonstrating the issue.
The text was updated successfully, but these errors were encountered: