[xquery-talk] Namespace conflict ?
Michael Kay
mike at saxonica.com
Wed Sep 17 03:15:56 PDT 2014
> Christian, thank you for your lines.
>
>> 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.
>
> When I prefix the new name, it works, even though the namespace binding is the same.
A namespace binding is a (prefix, uri) pair, so when you prefix the name there is a new (prefix, uri) pair which doesn't confllct with any existing (prefix, uri) pair. Does that clarify?
Michael Kay
Saxonica
>
> 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', “gym: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>
>
> I cannot see the namespace conflict.
> Thanks anyway
> Always
> Leo
>
>
>
>
>>
>> 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
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
More information about the talk
mailing list