Lucy
Lucy

Reputation: 491

Getting element names using XPath/XQuery

having the following XML sample document, I need to issue an XPath/XQuery expression to get the element names for every children of a CD element.

<CD>
  <TITLE>Empire Burlesque</TITLE>
  <ARTIST>Bob Dylan</ARTIST>
  <COUNTRY>USA</COUNTRY>
  <COMPANY>Columbia</COMPANY>
  <PRICE>10.90</PRICE>
  <YEAR>1985</YEAR>
</CD>

So I need the query to return TITLE, ARTIST, COUNTRY, COUNTRY, PRICE, YEAR , any one can help please? thanks

Upvotes: 10

Views: 23251

Answers (2)

Bozhkov Alex
Bozhkov Alex

Reputation: 1

Try /\*/name()
e.g. for Oracle use

XMLCast(XMLQuery('/*/name()' PASSING db_some_field_name RETURNING CONTENT) AS VARCHAR2(4000))

Upvotes: -1

Michael Kay
Michael Kay

Reputation: 163262

/CD/*/name()

(padded out because StackOverflow doesn't like short answers)

Upvotes: 19

Related Questions