Further development of the XPath expression proposed by Michael Kay (it seems like a simplification) also handles unsupported element names belonging to the default namespace:
distinct-values(//*[namespace-uri()] /concat(local-name(), ', ', substring-before(name(), ':'), ', ', namespace-uri(), '
' ) )
When this XPath expression is evaluated in the following document (provided, but with an element added, which is in the default namespace):
<ns1:create xmlns:ns1="http://predic8.com/wsdl/material/ArticleService/1/"> <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/"> <ns1:id>1</ns1:id> <description>bar</description> <name>foo</name> <ns1:price> <amount>00.00</amount> <currency>USD</currency> </ns1:price> <ns1:price> <amount>11.11</amount> <currency>AUD</currency> </ns1:price> </ns1:article> <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/"> <ns1:id>2</ns1:id> <description>some name</description> <name>some description</name> <ns1:price> <amount>00.01</amount> <currency>USD</currency> </ns1:price> <quality xmlns="my:q">high</quality> </ns1:article> </ns1:create>
required, the correct result is obtained :
create, ns1, http://predic8.com/wsdl/material/ArticleService/1/ article, ns1, xmlns:ns1='http://predic8.com/material/1/ id, ns1, xmlns:ns1='http://predic8.com/material/1/ price, ns1, xmlns:ns1='http://predic8.com/material/1/ quality, , my:q
Another minor improvement is also to create namespace data for attribute names:
distinct-values(//(*|@*)[namespace-uri()] /concat(if(. intersect ../@*) then '@' else (), local-name(), ', ', substring-before(name(), ':'), ', ', namespace-uri(), '
' ) )
When an XPath expression is evaluated in the following XML document (previous (above) with the xml:lang attribute added on one of the article elements):
<ns1:create xmlns:ns1="http://predic8.com/wsdl/material/ArticleService/1/"> <ns1:article xml:lang="en-us" xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/"> <ns1:id>1</ns1:id> <description>bar</description> <name>foo</name> <ns1:price> <amount>00.00</amount> <currency>USD</currency> </ns1:price> <ns1:price> <amount>11.11</amount> <currency>AUD</currency> </ns1:price> </ns1:article> <ns1:article xmlns:ns1="xmlns:ns1='http://predic8.com/material/1/"> <ns1:id>2</ns1:id> <description>some name</description> <name>some description</name> <ns1:price> <amount>00.01</amount> <currency>USD</currency> </ns1:price> <quality xmlns="my:q">high</quality> </ns1:article> </ns1:create>
again the correct result is obtained:
create, ns1, http://predic8.com/wsdl/material/ArticleService/1/ article, ns1, xmlns:ns1='http://predic8.com/material/1/ @lang, xml, http://www.w3.org/XML/1998/namespace id, ns1, xmlns:ns1='http://predic8.com/material/1/ price, ns1, xmlns:ns1='http://predic8.com/material/1/ quality, , my:q