Quantcast

add the xmlns attribute to the root element of a document

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

add the xmlns attribute to the root element of a document

Alfredo Cosco
Hi all,

[sorry for the two messages but in the previous I forgot the subject]

I'm using exist-db 2.2 stable

I have a collection of documents with a markup like this:

<mydocument>
    <meta>
        <doctitle>Lorem ipsum 2</doctitle>
    </meta>
    <text>Dolor sit amet</text>
</mydocument>

Now I have to add an xmlns attribute to document root, like this:

<mydocument xmlns="blah">

After a day of troubles I discovered that xmlns in the root element is not editable/updatable/replaceable without rewriting the document so I managed something dirty and easy like this:
------------------------------------------------------------------------------
let $doc:= doc("/db/apps/myapp/data/test/doc.xml")
let $old:= $doc/mydocument/*

let $new :=<mydocument xmlns="blah">{$old}</mydocument>

let $store:=xmldb:store("/db/apps/ratest/data/test/", "doc.xml", $new)

return
 $doc
-------------------------------------------------------------------------------

Wow, the result in eXide console is wonderful:
<mydocument xmlns="blah">
  <meta>
    <doctitle>Lorem ipsum 2</doctitle>
  </meta>
  <doctitle>Lorem ipsum 2</doctitle>
  <text>Dolor sit amet</text>
</mydocument>

but when I open the file in the editor it is like this:

<mydocument xmlns="blah">
    <meta xmlns="">
        <doctitle>Lorem ipsum 2</doctitle>
    </meta>
    <text xmlns="">Dolor sit amet</text>
</mydocument>

As you can see there are empty xmlns attributes on the children of the root.

Why? How can I avoid this? 

Thanks,
Alfredo


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: add the xmlns attribute to the root element of a document

Martin Holmes
Hi Alfredo,

What you see appears to me to be the correct behaviour. All the elements
in your original document are in the empty namespace; you're adding a
new root element in your "blah" namespace, but then copying all the old
elements (with their original namespace) into it; therefore they receive
empty namespace declarations.

You could write some XSLT-style XQuery with a recursive function that
rewrites all elements in the new namespace, or you could download the
documents, fix them with a search-and-replace or some real XSLT, and
upload them back into the database.

Cheers,
Martin

On 2017-02-16 11:38 AM, Alfredo Cosco wrote:

> Hi all,
>
> [sorry for the two messages but in the previous I forgot the subject]
>
> I'm using exist-db 2.2 stable
>
> I have a collection of documents with a markup like this:
>
> <mydocument>
>     <meta>
>         <doctitle>Lorem ipsum 2</doctitle>
>     </meta>
>     <text>Dolor sit amet</text>
> </mydocument>
>
> Now I have to add an xmlns attribute to document root, like this:
>
> <mydocument xmlns="blah">
>
> After a day of troubles I discovered that xmlns in the root element is
> not editable/updatable/replaceable without rewriting the document so I
> managed something dirty and easy like this:
> ------------------------------------------------------------------------------
> let $doc:= doc("/db/apps/myapp/data/test/doc.xml")
> let $old:= $doc/mydocument/*
>
> let $new :=<mydocument xmlns="blah">{$old}</mydocument>
>
> let $store:=xmldb:store("/db/apps/ratest/data/test/", "doc.xml", $new)
>
> return
>  $doc
> -------------------------------------------------------------------------------
>
> Wow, the result in eXide console is wonderful:
> <mydocument xmlns="blah">
>   <meta>
>     <doctitle>Lorem ipsum 2</doctitle>
>   </meta>
>   <doctitle>Lorem ipsum 2</doctitle>
>   <text>Dolor sit amet</text>
> </mydocument>
>
> but when I open the file in the editor it is like this:
>
> <mydocument xmlns="blah">
>     <meta xmlns="">
>         <doctitle>Lorem ipsum 2</doctitle>
>     </meta>
>     <text xmlns="">Dolor sit amet</text>
> </mydocument>
>
> As you can see there are empty xmlns attributes on the children of the root.
>
> Why? How can I avoid this?
>
> Thanks,
> Alfredo
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Exist-open mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/exist-open
>



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: add the xmlns attribute to the root element of a document

Joe Wicentowski
In reply to this post by Alfredo Cosco
Hi Alfredo,

eXide's output pane has a known bug when it comes to the display of
empty namespaces: https://github.com/wolfgangmm/eXide/issues/108.  I
have some ideas for fixing this but haven't been able to find a fix
that covers all cases.

(After taking another stab at this tonight, I came up with a better
way to approach such bugs/quirks with the way eXide does syntax
highlighting on query results, which I've proposed at
https://github.com/wolfgangmm/eXide/issues/147.)

In the meantime, apologies to anyone who is bit by the issue in #108.

Joe

> Wow, the result in eXide console is wonderful:
> <mydocument xmlns="blah">
>   <meta>
>     <doctitle>Lorem ipsum 2</doctitle>
>   </meta>
>   <doctitle>Lorem ipsum 2</doctitle>
>   <text>Dolor sit amet</text>
> </mydocument>
>
> but when I open the file in the editor it is like this:
>
> <mydocument xmlns="blah">
>     <meta xmlns="">
>         <doctitle>Lorem ipsum 2</doctitle>
>     </meta>
>     <text xmlns="">Dolor sit amet</text>
> </mydocument>
>
> As you can see there are empty xmlns attributes on the children of the root.
>
> Why? How can I avoid this?

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: add the xmlns attribute to the root element of a document

Michael Joyce-2
In reply to this post by Martin Holmes
If the functx library is available, there's change-element-ns-deep() which does all of this for you.


Michael

On Feb 18, 2017, at 2:42 PM, Martin Holmes <[hidden email]> wrote:

Hi Alfredo,

What you see appears to me to be the correct behaviour. All the elements
in your original document are in the empty namespace; you're adding a
new root element in your "blah" namespace, but then copying all the old
elements (with their original namespace) into it; therefore they receive
empty namespace declarations.

You could write some XSLT-style XQuery with a recursive function that
rewrites all elements in the new namespace, or you could download the
documents, fix them with a search-and-replace or some real XSLT, and
upload them back into the database.

Cheers,
Martin

On 2017-02-16 11:38 AM, Alfredo Cosco wrote:
Hi all,

[sorry for the two messages but in the previous I forgot the subject]

I'm using exist-db 2.2 stable

I have a collection of documents with a markup like this:

<mydocument>
   <meta>
       <doctitle>Lorem ipsum 2</doctitle>
   </meta>
   <text>Dolor sit amet</text>
</mydocument>

Now I have to add an xmlns attribute to document root, like this:

<mydocument xmlns="blah">

After a day of troubles I discovered that xmlns in the root element is
not editable/updatable/replaceable without rewriting the document so I
managed something dirty and easy like this:
------------------------------------------------------------------------------
let $doc:= doc("/db/apps/myapp/data/test/doc.xml")
let $old:= $doc/mydocument/*

let $new :=<mydocument xmlns="blah">{$old}</mydocument>

let $store:=xmldb:store("/db/apps/ratest/data/test/", "doc.xml", $new)

return
$doc
-------------------------------------------------------------------------------

Wow, the result in eXide console is wonderful:
<mydocument xmlns="blah">
 <meta>
   <doctitle>Lorem ipsum 2</doctitle>
 </meta>
 <doctitle>Lorem ipsum 2</doctitle>
 <text>Dolor sit amet</text>
</mydocument>

but when I open the file in the editor it is like this:

<mydocument xmlns="blah">
   <meta xmlns="">
       <doctitle>Lorem ipsum 2</doctitle>
   </meta>
   <text xmlns="">Dolor sit amet</text>
</mydocument>

As you can see there are empty xmlns attributes on the children of the root.

Why? How can I avoid this?

Thanks,
Alfredo



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot



_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: add the xmlns attribute to the root element of a document

Alfredo Cosco
Hello,
thanks you for your replies, i solved adding to any document root:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../infoed.xsd"

easier to insert and without effects on original x-schema

Bye,
Alfredo

2017-02-19 15:46 GMT+01:00 Michael Joyce <[hidden email]>:
If the functx library is available, there's change-element-ns-deep() which does all of this for you.


Michael

On Feb 18, 2017, at 2:42 PM, Martin Holmes <[hidden email]> wrote:

Hi Alfredo,

What you see appears to me to be the correct behaviour. All the elements
in your original document are in the empty namespace; you're adding a
new root element in your "blah" namespace, but then copying all the old
elements (with their original namespace) into it; therefore they receive
empty namespace declarations.

You could write some XSLT-style XQuery with a recursive function that
rewrites all elements in the new namespace, or you could download the
documents, fix them with a search-and-replace or some real XSLT, and
upload them back into the database.

Cheers,
Martin

On 2017-02-16 11:38 AM, Alfredo Cosco wrote:
Hi all,

[sorry for the two messages but in the previous I forgot the subject]

I'm using exist-db 2.2 stable

I have a collection of documents with a markup like this:

<mydocument>
   <meta>
       <doctitle>Lorem ipsum 2</doctitle>
   </meta>
   <text>Dolor sit amet</text>
</mydocument>

Now I have to add an xmlns attribute to document root, like this:

<mydocument xmlns="blah">

After a day of troubles I discovered that xmlns in the root element is
not editable/updatable/replaceable without rewriting the document so I
managed something dirty and easy like this:
------------------------------------------------------------------------------
let $doc:= doc("/db/apps/myapp/data/test/doc.xml")
let $old:= $doc/mydocument/*

let $new :=<mydocument xmlns="blah">{$old}</mydocument>

let $store:=xmldb:store("/db/apps/ratest/data/test/", "doc.xml", $new)

return
$doc
-------------------------------------------------------------------------------

Wow, the result in eXide console is wonderful:
<mydocument xmlns="blah">
 <meta>
   <doctitle>Lorem ipsum 2</doctitle>
 </meta>
 <doctitle>Lorem ipsum 2</doctitle>
 <text>Dolor sit amet</text>
</mydocument>

but when I open the file in the editor it is like this:

<mydocument xmlns="blah">
   <meta xmlns="">
       <doctitle>Lorem ipsum 2</doctitle>
   </meta>
   <text xmlns="">Dolor sit amet</text>
</mydocument>

As you can see there are empty xmlns attributes on the children of the root.

Why? How can I avoid this?

Thanks,
Alfredo



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot



_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Loading...