[xquery-talk] Namespace conflict ?
Christian Grün
christian.gruen at gmail.com
Wed Sep 17 01:34:09 PDT 2014
Hi Leo,
the reason is that the XML document in your first example does not
have any namespace; so there won't be any conflicts. Instead, the new
namespace will be assigned to the addressed element.
This is different in the second case. The specification [1] says that
"If the namespace binding of $QName conflicts with any namespace
binding in the namespaces property of $target, a dynamic error is
raised [err:XUDY0023].". This is why an error is raised if a namespace
already exists.
Hope this helps,
Christian
[1] http://www.w3.org/TR/xquery-update-10/#id-rename
>> The problem is that your original document
>> uses the default namespace "http://www.mygym.com", and your query uses
>> "http://www.gym.com". In other words, the error is raised because the
>> namespace binding of your target name conflicts with the existing
>> namespace binding.
>
> That I don't get.
>
> This works
> let $i:=(doc("FitnessCenter.xml")//Name)[1]
>
> return rename node $i as QName('http://www.gym.com', "Name")
> with
> <?xml version="1.0" encoding="UTF-8"?>
>
> <FitnessCenter>
> <Member Level="platinum">
> <Name>Jeff</Name>
> <FavoriteColor>lightgrey</FavoriteColor>
> </Member>
> </FitnessCenter>
>
> This not
>
> declare namespace gym='http://www.mygym.com';
>
> let $i:=(doc("FitnessCenter.xml")//gym:Name)[1]
>
> return rename node $i as QName('http://www.gym.com', "Name")
> with
> <?xml version="1.0" encoding="UTF-8"?>
>
> <FitnessCenter xmlns="http://www.mygym.com">
> <Member Level="platinum">
> <Name>Jeff</Name>
> <FavoriteColor>lightgrey</FavoriteColor>
> </Member>
> </FitnessCenter>
>
>
>
> Why should that conflict?
> Always
> Leo
>
>
>
>
>>
>> Here is a recursive approach to change the default namespace of a document:
>> ______________________________________
>>
>> declare function local:update($root as node(), $ns as xs:string) {
>> if($root instance of element()) then (
>> element { QName($ns, local-name($root)) } {
>> $root/@*,
>> for $node in $root/node()
>> return local:update($node, $ns)
>> }
>> ) else (
>> $root
>> )
>> };
>>
>> let $ns := 'http://www.gym.com'
>> let $root := doc("FitnessCenter.xml")/*
>> let $updated := local:update($root, $ns)
>> return replace node $root with $updated
>> ______________________________________
>>
>> Hope this helps,
>> Christian
>>
>>
>>
>> On Tue, Sep 16, 2014 at 12:10 PM, Leo Studer <leo.studer at varioweb.ch> wrote:
>>> Hello
>>>
>>> I use the following query with Saxon-EE xQuery 9.5.1.5 in Oxygen.
>>>
>>> for $i in doc('FitnessCenter.xml')//*
>>> return rename node $i as QName('http://www.gym.com', local-name($i))
>>>
>>>
>>> on the following file:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <FitnessCenter xmlns="http://www.mygym.com">
>>> <Member Level="platinum">
>>> <Name>Jeff</Name>
>>> <FavoriteColor>lightgrey</FavoriteColor>
>>> </Member>
>>> <Member Level="gold">
>>> <Name>David</Name>
>>> <FavoriteColor>lightblue</FavoriteColor>
>>> </Member>
>>> </FitnessCenter>
>>>
>>> and get the following error: new name conflicts with existing namespace binding
>>>
>>>
>>> I thought the function local-name() produces an output without namespace binding? Can anyone explain?
>>>
>>> Thanks in advance
>>> Leo
>>>
>>>
>>> _______________________________________________
>>> talk at x-query.com
>>> http://x-query.com/mailman/listinfo/talk
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
More information about the talk
mailing list