user4542931
user4542931

Reputation:

Renaming node with namespace

Hi I have an issue with namespaces

My XML is as follows:

<earnings xmlns="http://www.dppvgu.com" currency="USD">
  <distribution>15002111</distribution>
  <ticket_sales>
    <distribution num="2">24450144</distribution>
    <distribution num="3">12057133</distribution>
  </ticket_sales>
  <digital_sales>
    <ppv_sales>19220907</ppv_sales>
    <stream_sales>49725265</stream_sales>
    <disc_sales>15082021</disc_sales>
  </digital_sales>
</earnings>

I would like to rename the node <distribution>15002111</distribution> using the following command:

for $doc in doc("earnings.xml")/*[local-name() = 'earnings']/*[local-name() = 'distribution']
return rename node $doc as 'postbox'

I get the following error: [XUDY0023] Conflicts with existing namespaces.

How do I resolve the issue? Please help

Upvotes: 0

Views: 167

Answers (1)

har07
har07

Reputation: 89295

Try using QName() to specify the new name to be in the default namespace :

for $doc in doc("earnings.xml")/*[local-name() = 'earnings']/*[local-name() = 'distribution']
return rename node $doc as QName('http://www.dppvgu.com','postbox')

or using QName() in combination with namespace-uri() to avoid hardcoding the namespace :

for $doc in doc("earnings.xml")/*[local-name() = 'earnings']/*[local-name() = 'distribution']
return rename node $doc as QName(namespace-uri($doc),'postbox')

Upvotes: 1

Related Questions