Cannot copy xmlns:* attributes

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot copy xmlns:* attributes

Jean-Baptiste Quenot-2
Hello,

Bug or feature?  It's impossible to copy the xmlns:* attributes
with the « $doc/@* » predicate of the following XQuery:

-----------------------------------------------------------------
let $doc := <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a></doc>

return
<doc>
{
        $doc/@*,
        $doc/node()
}
</doc>
-----------------------------------------------------------------

Here is the resulting document:

-----------------------------------------------------------------
<doc b="b">Hello <a:a xmlns:a="a">World!</a:a>
</doc>
-----------------------------------------------------------------

At least I would expect the xmlns:a prefix mapping to be inserted
on the root element like this:

-----------------------------------------------------------------
<doc xmlns:a="a" b="b">Hello <a:a>World!</a:a>
</doc>
-----------------------------------------------------------------

Thanks in advance,
--
Jean-Baptiste Quenot
Systèmes d'Information
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Cannot copy xmlns:* attributes

Jean-Marc Vanel-3
Jean-Baptiste Quenot wrote:

>Hello,
>  
>
Bonjour JB

>Bug or feature?  
>
feature !

According to the XML Namespace W3C specification, xmlns:* are not treated like real attributes, they can be put at any relevant level.

In your case, tha prefix mapping is only needed at the inner level . So
it's perfectly legal to have it here .

>It's impossible to copy the xmlns:* attributes
>with the « $doc/@* » predicate of the following XQuery:
>
>-----------------------------------------------------------------
>let $doc := <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a></doc>
>
>return
><doc>
>{
>        $doc/@*,
>        $doc/node()
>}
></doc>
>-----------------------------------------------------------------
>
>Here is the resulting document:
>
>-----------------------------------------------------------------
><doc b="b">Hello <a:a xmlns:a="a">World!</a:a>
></doc>
>-----------------------------------------------------------------
>
>At least I would expect the xmlns:a prefix mapping to be inserted
>on the root element like this:
>
>-----------------------------------------------------------------
><doc xmlns:a="a" b="b">Hello <a:a>World!</a:a>
></doc>
>  
>
What for ?

--
Jean-Marc Vanel
Conseil et Services / développement & intégration logiciels
Logiciel libre, Web, Java, XML ...
A la pointe de la technique, au service des projets
http://jmvanel.free.fr/ ===) CV, software resources

Mes journaux:
- sujets généraux en Français: http://jmvanel.free.fr/Block-note.html
- sujets informatiques en Français: http://jmvanel.free.fr/notes-informatiques.html
- computer science diary : http://jmvanel.free.fr/computer-notes.html

Worldwide Botanical Knowledge Base
http://wwbota.free.fr/ 
test XML query engine: http://jmvanel.free.fr/protea.html




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Cannot copy xmlns:* attributes

Pierrick Brihaye-2
Hi,

Jean-Marc Vanel wrote:

 >> Bug or feature?
 > feature !

Yes. Saxon outputs the same result.

In short, prefixes can't be replaced by wildcards.

 > In your case, tha prefix mapping is only needed at the inner level . So
 > it's perfectly legal to have it here .

It's a serialization matter : the namespace is declared where it is used
first...

 >> At least I would expect the xmlns:a prefix mapping to be inserted
 >> on the root element like this:
 >>
 >> -----------------------------------------------------------------
 >> <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a>
 >> </doc>

... unless you want it before, using the following construct for example :

let $doc := <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a></doc>

return
<doc xmlns:a="a">
{
         $doc/@*,
         $doc/node()
}
</doc>

Cheers,

--
Pierrick Brihaye, informaticien
Service régional de l'Inventaire
DRAC Bretagne
mailto:[hidden email]
+33 (0)2 99 29 67 78


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Cannot copy xmlns:* attributes

Jean-Baptiste Quenot-2
In reply to this post by Jean-Marc Vanel-3
* Jean-Marc Vanel:

> >Here is the resulting document:
> >
> >-----------------------------------------------------------------
> ><doc b="b">Hello <a:a xmlns:a="a">World!</a:a>
> ></doc>
> >-----------------------------------------------------------------
> >
> >At least I would expect the xmlns:a prefix mapping to be inserted
> >on the root element like this:
> >
> >-----------------------------------------------------------------
> ><doc xmlns:a="a" b="b">Hello <a:a>World!</a:a>
> ></doc>
> >

> What for ?

Because I need to load  that document with JXPathContext in Apache
Commons commons-jxpath,  which cannot handle nodes  in a namespace
if the latter is not declared on the root element.

And also because  repeating the namespace prefix  mapping on every
node makes the document unreadable and unnecessarily fat.

Maybe I just need to put a SAX filter after the XQuery?  Otherwise
I need to repeat the namespace prefix mappings on the root element
of all XQueries.

Thanks for your help,
--
Jean-Baptiste Quenot
Systèmes d'Information
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Cannot copy xmlns:* attributes

Jean-Baptiste Quenot-2
In reply to this post by Pierrick Brihaye-2
* Pierrick Brihaye:

> > > At least I would expect the xmlns:a prefix mapping to be inserted
> > > on the root element like this:
> > >
> > > -----------------------------------------------------------------
> > > <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a>
> > > </doc>
>
> ... unless you want it before, using the following construct for example :
>
> let $doc := <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a></doc>

That's exactly what I try to avoid, because I don't know what
namespaces are used in the documents.
--
Jean-Baptiste Quenot
Systèmes d'Information
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Cannot copy xmlns:* attributes

Pierrick Brihaye-2
In reply to this post by Jean-Baptiste Quenot-2
Hi,

Jean-Baptiste Quenot wrote:

> Because I need to load  that document with JXPathContext in Apache
> Commons commons-jxpath,  which cannot handle nodes  in a namespace
> if the latter is not declared on the root element.

Change this tool :-) or consider what is illustrated by this example :

let $doc := <doc xmlns:a="a" b="b">Hello <a:a>World!</a:a></doc>
for $i in fn:in-scope-prefixes($doc)
return <ns><prefix>{$i}</prefix><uri>{fn:namespace-uri-for-prefix($i,
$doc)}</uri></ns>

Works well in Saxon but needs the developpement of
fn:in-scope-prefixes() for eXist.

Cheers,

--
Pierrick Brihaye, informaticien
Service régional de l'Inventaire
DRAC Bretagne
mailto:[hidden email]
+33 (0)2 99 29 67 78


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open