Discussion:
Namespace conflict ?
Leo Studer
2014-09-16 10:10:55 UTC
Permalink
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


_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinf
Christian Grün
2014-09-16 10:32:49 UTC
Permalink
Hi Leo,
Post by Leo Studer
I thought the function local-name() produces an output without namespace binding? Can anyone explain?
You are completely right. 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.

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
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Leo Studer
2014-09-17 06:24:36 UTC
Permalink
Hi Christian

thank you for your input.
Post by Christian Grün
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
Post by Christian Grün
______________________________________
declare function local:update($root as node(), $ns as xs:string) {
if($root instance of element()) then (
element { QName($ns, local-name($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
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Christian Grün
2014-09-17 08:34:09 UTC
Permalink
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
Post by Christian Grün
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
Post by Christian Grün
______________________________________
declare function local:update($root as node(), $ns as xs:string) {
if($root instance of element()) then (
element { QName($ns, local-name($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
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Leo Studer
2014-09-17 10:07:27 UTC
Permalink
Christian, thank you for your lines.
Post by Christian Grün
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.

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
Post by Christian Grün
Hope this helps,
Christian
[1] http://www.w3.org/TR/xquery-update-10/#id-rename
Post by Christian Grün
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
Post by Christian Grün
______________________________________
declare function local:update($root as node(), $ns as xs:string) {
if($root instance of element()) then (
element { QName($ns, local-name($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
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2014-09-17 10:15:56 UTC
Permalink
Post by Leo Studer
Christian, thank you for your lines.
Post by Christian Grün
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
Post by Leo Studer
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
Post by Christian Grün
Hope this helps,
Christian
[1] http://www.w3.org/TR/xquery-update-10/#id-rename
Post by Christian Grün
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
Post by Christian Grün
______________________________________
declare function local:update($root as node(), $ns as xs:string) {
if($root instance of element()) then (
element { QName($ns, local-name($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
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Leo Studer
2014-09-17 15:19:41 UTC
Permalink
Thank you Michael. In this view, changing the default namespace, the pair (“”,uri1) to (“”, uri2) is a potential conflict, I can see that.
However, adding a default namespace when no namespace is defined - in the (prefix, uri) view, I would see that as changing (“”,””) to (“”, uri1) - seems quite similar to me...

Don’t worry, I was just intrigued ;-)

Always
Leo
Post by Michael Kay
Post by Leo Studer
Christian, thank you for your lines.
Post by Christian Grün
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
Post by Leo Studer
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
Post by Christian Grün
Hope this helps,
Christian
[1] http://www.w3.org/TR/xquery-update-10/#id-rename
Post by Christian Grün
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
Post by Christian Grün
______________________________________
declare function local:update($root as node(), $ns as xs:string) {
if($root instance of element()) then (
element { QName($ns, local-name($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
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2014-09-16 10:38:09 UTC
Permalink
Is the new namespace really the same as the old, or is that a typo?

If the new namespace is different, say 'http://www.gym.com/2', then there's a problem, because an element can't contain both the namespace declarations xmlns='http://www.gym.com/2' and 'http://www.gym.com'.

I have to admit my memory of the detail of XQuery Update is very hazy, I haven't done any work in this area for several years, so I'll have to refresh it, but it would be nice first to have confirmation of whether the question is correct as written.

Michael Kay
Saxonica
mike-JkSD5nQpfvpWk0Htik3J/***@public.gmane.org
+44 (0) 118 946 5893
Post by Leo Studer
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))
<?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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2014-09-16 12:02:43 UTC
Permalink
Post by Michael Kay
Is the new namespace really the same as the old, or is that a typo?
Sorry, I need to get new specs.

Michael Kay
Saxonica
Loading...