Problems adding content to an xml file in exist using orbeon

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

Problems adding content to an xml file in exist using orbeon

teppen
Hi, I'm new to Orbeon and XPL so I'm hoping you folks can help me. I've made an registration form (XForms) which is posted to my xpl. I want to save these data into an existing 'customers.xml' in my exist database. In other words add a new Customer and User in customers.xml.

I've tried to use the xmldb-update processor. Everything seems to go fine in my xpl, but i get an error when the update is executed:
org.apache.xmlrpc.XmlRpcException: org.exist.xquery.XPathException: XPST0081: No namespace defined for prefix dm

I don't know where to put the namespace declaration, I've put it everywhere in my xpl without success. If I omit the namespace prefix in the select statements in xu:insert-after i get no error but the customers file is not updated. How, and/or where, should I put the namespace declaration?

I don't know if this is the correct approach to do what I'm trying to do. I guess there are several ways to add content to an xml file in Orbeon, but I haven't found any examples similar to what I want. I would appreciate if someone could point me in the right direction. Below are some of my code. Thanks in advance.

-Tommy Skarateppen

The customer.xml in exist-db looks like this (shortened):

<Static-Data xmlns="http://www.myns.no/data-model">
        <Companies>
                <Company>
                ...
                </Company>
                <Company>
                ...
                </Company>
        </Companies>
        <Users>
                <User>
                ...
                </User>
                <User>
                ...
                <User>
        </Users>
</Static-Data>

The instance posted from my form looks like this:

<Static-Data xmlns="http://www.myns.no/data-model">
    <Companies>
        <Company>
            <Name>My Company</Name>
            <Address1>My street 17</Address1>
            <Address2/>
            <PO-Box/>
            <ZipCode>1234</ZipCode>
            <City>My City</City>
            <Phone>12345678</Phone>
            <Discount/>
            <VAT-Number/>
            <WebSite/>
            <Invoice/>
        </Company>
    </Companies>
    <Users>
        <User>
                [hidden email]
                <Company ref=""/>
                <FirstName>John</FirstName>
                <LastName>Olsen</LastName>
                <Phone/>
                <Password>mysecretpassword</Password>
                <Password2/>
                <OpenIdUrl/>
                <IP4-Ranges>
                        <Matcher segm1="" segm2="" segm3="" segm4=""/>
                </IP4-Ranges>
                <Subscriptions>
                        <Canceled>false</Canceled>
                        <StartDate/>
                        <ExpireDate/>
                        <Calculations updated="">
                                <MaxWebSessions>1</MaxWebSessions>
                                <Book ref="mybook"/>
                        </Calculations>
                </Subscriptions>
        </User>
    </Users>
</Static-Data>


Snippet from my xpl:

<p:processor name="oxf:xslt-2.0">
    <p:input name="data" href="#instance"/>
    <p:input name="config">
        <xdb:update collection="/db/abbsys" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0">
            <xu:modifications version="1.0">
                <xu:insert-after select="/dm:Static-Data/dm:Companies/dm:Company[last()]" xmlns:dm="http://www.myns.no/data-model">
                    <xsl:copy-of select="/dm:Static-Data/dm:Companies/dm:Company"/>
                </xu:insert-after>
                <xu:insert-after select="/dm:Static-Data/dm:Users/dm:User[last()]" xmlns:dm="http://www.myns.no/data-model">
                    <xsl:copy-of select="/dm:Static-Data/dm:Users/dm:User"/>
                </xu:insert-after>
            </xu:modifications>
        </xdb:update>                   
    </p:input>
    <p:output name="data" id="update"/>
</p:processor>

<p:processor name="oxf:xmldb-update">
    <p:input name="datasource" href="../datasource.xml"/>
    <p:input name="query" href="#update" debug="xmldb-update"/>
</p:processor>


Here's a snippet of the xmldb-update debugging output from the orbeon.log

<xdb:update xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:dm="http://www.myns.no/data-model" xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:xu="http://www.xmldb.org/xupdate" collection="/db/abbsys">
    <xu:modifications version="1.0">
        <xu:insert-after select="/dm:Static-Data/dm:Companies/dm:Company[last()]">
            <Company xmlns="http://www.myns.no/data-model">
                <Name>My Company</Name>
                <Address1>My street 17</Address1>
                <Address2/>
                <PO-Box/>
                <ZipCode>1234</ZipCode>
                <City>My City</City>
                <Phone>12345678</Phone>
                <Discount/>
                <VAT-Number/>
                <WebSite/>
                <Invoice/>
            </Company>
        </xu:insert-after>
        <xu:insert-after select="/dm:Static-Data/dm:Users/dm:User[last()]">
            <User xmlns="http://www.myns.no/data-model">
                [hidden email]
                <Company ref=""/>
                <FirstName>John</FirstName>
                <LastName>Olsen</LastName>
                <Phone/>
                <Password>mysecretpassword</Password>
                <Password2/>
                <OpenIdUrl/>
                <IP4-Ranges>
                    <Matcher segm1="" segm2="" segm3="" segm4=""/>
                </IP4-Ranges>
                <Subscriptions>
                    <Canceled>false</Canceled>
                    <StartDate/>
                    <ExpireDate/>
                    <Calculations updated="">
                        <MaxWebSessions>1</MaxWebSessions>
                        <Book ref="mybook"/>
                    </Calculations>
                </Subscriptions>
            </User>
        </xu:insert-after>
    </xu:modifications>
</xdb:update>
Reply | Threaded
Open this post in threaded view
|

RE: Problems adding content to an xml file in exist using orbeon

Steve Bayliss
I'd put it on your xu:modifications element in your processor in the xpl, ie

 <xu:modifications version="1.0" xmlns:dm="http://www.myns.no/data-model">

Steve

-----Original Message-----
From: teppen [mailto:[hidden email]]
Sent: 26 October 2009 13:41
To: [hidden email]
Subject: [ops-users] Problems adding content to an xml file in exist using
orbeon



Hi, I'm new to Orbeon and XPL so I'm hoping you folks can help me. I've made
an registration form (XForms) which is posted to my xpl. I want to save
these data into an existing 'customers.xml' in my exist database. In other
words add a new Customer and User in customers.xml.

I've tried to use the xmldb-update processor. Everything seems to go fine in
my xpl, but i get an error when the update is executed:
org.apache.xmlrpc.XmlRpcException: org.exist.xquery.XPathException:
XPST0081: No namespace defined for prefix dm

I don't know where to put the namespace declaration, I've put it everywhere
in my xpl without success. If I omit the namespace prefix in the select
statements in xu:insert-after i get no error but the customers file is not
updated. How, and/or where, should I put the namespace declaration?

I don't know if this is the correct approach to do what I'm trying to do. I
guess there are several ways to add content to an xml file in Orbeon, but I
haven't found any examples similar to what I want. I would appreciate if
someone could point me in the right direction. Below are some of my code.
Thanks in advance.

-Tommy Skarateppen

The customer.xml in exist-db looks like this (shortened):

<Static-Data xmlns="http://www.myns.no/data-model">
        <Companies>
                <Company>
                ...
                </Company>
                <Company>
                ...
                </Company>
        </Companies>
        <Users>
                <User>
                ...
                </User>
                <User>
                ...
                <User>
        </Users>
</Static-Data>

The instance posted from my form looks like this:

<Static-Data xmlns="http://www.myns.no/data-model">
    <Companies>
        <Company>
            <Name>My Company</Name>
            <Address1>My street 17</Address1>
            <Address2/>
            <PO-Box/>
            <ZipCode>1234</ZipCode>
            <City>My City</City>
            <Phone>12345678</Phone>
            <Discount/>
            <VAT-Number/>
            <WebSite/>
            <Invoice/>
        </Company>
    </Companies>
    <Users>
        <User>
                [hidden email]
                <Company ref=""/>
                <FirstName>John</FirstName>
                <LastName>Olsen</LastName>
                <Phone/>
                <Password>mysecretpassword</Password>
                <Password2/>
                <OpenIdUrl/>
                <IP4-Ranges>
                        <Matcher segm1="" segm2="" segm3="" segm4=""/>
                </IP4-Ranges>
                <Subscriptions>
                        <Canceled>false</Canceled>
                        <StartDate/>
                        <ExpireDate/>
                        <Calculations updated="">
                                <MaxWebSessions>1</MaxWebSessions>
                                <Book ref="mybook"/>
                        </Calculations>
                </Subscriptions>
        </User>
    </Users>
</Static-Data>


Snippet from my xpl:

<p:processor name="oxf:xslt-2.0">
    <p:input name="data" href="#instance"/>
    <p:input name="config">
        <xdb:update collection="/db/abbsys"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0">
            <xu:modifications version="1.0">
                <xu:insert-after
select="/dm:Static-Data/dm:Companies/dm:Company[last()]"
xmlns:dm="http://www.myns.no/data-model">
                    <xsl:copy-of
select="/dm:Static-Data/dm:Companies/dm:Company"/>
                </xu:insert-after>
                <xu:insert-after
select="/dm:Static-Data/dm:Users/dm:User[last()]"
xmlns:dm="http://www.myns.no/data-model">
                    <xsl:copy-of select="/dm:Static-Data/dm:Users/dm:User"/>
                </xu:insert-after>
            </xu:modifications>
        </xdb:update>                    
    </p:input>
    <p:output name="data" id="update"/>
</p:processor>

<p:processor name="oxf:xmldb-update">
    <p:input name="datasource" href="../datasource.xml"/>
    <p:input name="query" href="#update" debug="xmldb-update"/>
</p:processor>


Here's a snippet of the xmldb-update debugging output from the orbeon.log

<xdb:update xmlns:xdb="http://orbeon.org/oxf/xml/xmldb"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:dm="http://www.myns.no/data-model"
xmlns:exist="http://exist.sourceforge.net/NS/exist"
xmlns:xu="http://www.xmldb.org/xupdate" collection="/db/abbsys">
    <xu:modifications version="1.0">
        <xu:insert-after
select="/dm:Static-Data/dm:Companies/dm:Company[last()]">
            <Company xmlns="http://www.myns.no/data-model">
                <Name>My Company</Name>
                <Address1>My street 17</Address1>
                <Address2/>
                <PO-Box/>
                <ZipCode>1234</ZipCode>
                <City>My City</City>
                <Phone>12345678</Phone>
                <Discount/>
                <VAT-Number/>
                <WebSite/>
                <Invoice/>
            </Company>
        </xu:insert-after>
        <xu:insert-after select="/dm:Static-Data/dm:Users/dm:User[last()]">
            <User xmlns="http://www.myns.no/data-model">
                [hidden email]
                <Company ref=""/>
                <FirstName>John</FirstName>
                <LastName>Olsen</LastName>
                <Phone/>
                <Password>mysecretpassword</Password>
                <Password2/>
                <OpenIdUrl/>
                <IP4-Ranges>
                    <Matcher segm1="" segm2="" segm3="" segm4=""/>
                </IP4-Ranges>
                <Subscriptions>
                    <Canceled>false</Canceled>
                    <StartDate/>
                    <ExpireDate/>
                    <Calculations updated="">
                        <MaxWebSessions>1</MaxWebSessions>
                        <Book ref="mybook"/>
                    </Calculations>
                </Subscriptions>
            </User>
        </xu:insert-after>
    </xu:modifications>
</xdb:update>
--
View this message in context:
http://n4.nabble.com/Problems-adding-content-to-an-xml-file-in-exist-using-o
rbeon-tp276774p276774.html
Sent from the ObjectWeb OPS - Users mailing list archive at Nabble.com.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Problems adding content to an xml file in exist using orbeon

teppen
Thanks for your reply, Steve. I've tried that, but it doesn't work. When I look at the output from my xslt-2.0 processor in the orbeon.log file, the namespace declaration is removed, but the parent element <xdb:update> has the namespace declaration among with several others which is declared on the root element in my xpl.

Tommy


Steve Bayliss wrote
I'd put it on your xu:modifications element in your processor in the xpl, ie

 <xu:modifications version="1.0" xmlns:dm="http://www.myns.no/data-model">

Steve
Reply | Threaded
Open this post in threaded view
|

RE: RE: Problems adding content to an xml file in exist using orbeon

Steve Bayliss
Your xslt output actually looks ok; looks like something to do with how
xmldb-update is handling namespaces.  And I guess the xslt is seeing the
"select" element content purely as text, hence why it carries up the
namespace declaration to the top level rather than recognising the scope.

I think you need to use an <xu:namespace> element, similar to
<xsl:namespace> - see
http://www.orbeon.com/ops/doc/processors-xupdate#d66e228; the syntax should
be as per http://www.w3.org/TR/xslt20/#element-namespace

So I guess something like (I haven't tested this!)

<xu:insert-after select="/dm:Static-Data/dm:Companies/dm:Company[last()]">
  <xu:namespace name="dm" select="'http://www.myns.no/data-model'/>
  <xsl:copy-of select="/dm:Static-Data/dm:Companies/dm:Company"
xmlns:dm="http://www.myns.no/data-model"/>
</xu:insert-after>

(note you will need xmlns:dm on the xsl:copy-of element or xslt won't have a
namespace prefix declaration for dm)

Alternatively I think   <xu:namespace
name="dm">http://www.myns.no/data-model</xu:namespace> should work

And it should also be possible to use the <xsl:namespace> element as an
alternative to this.

If there are still problems with this I would suggest using this approach
but use different namespace prefixes in the "xu:" nodes from the "xsl:"
instructions (eg use
select="/dmx:Static-Data/dmx:Companies/dmx:Company[last()]" in
xu:insert-after and change the xu:namespace name attribute to "dmx").

Steve



-----Original Message-----
From: teppen [mailto:[hidden email]]
Sent: 27 October 2009 08:37
To: [hidden email]
Subject: [ops-users] RE: Problems adding content to an xml file in exist
using orbeon



Thanks for your reply, Steve. I've tried that, but it doesn't work. When I
look at the output from my xslt-2.0 processor in the orbeon.log file, the
namespace declaration is removed, but the parent element <xdb:update> has
the namespace declaration among with several others which is declared on the
root element in my xpl.

Tommy



Steve Bayliss wrote:
>
> I'd put it on your xu:modifications element in your processor in the xpl,
> ie
>
>  <xu:modifications version="1.0" xmlns:dm="http://www.myns.no/data-model">
>
> Steve
>
>

--
View this message in context:
http://n4.nabble.com/Problems-adding-content-to-an-xml-file-in-exist-using-o
rbeon-tp276774p277146.html
Sent from the ObjectWeb OPS - Users mailing list archive at Nabble.com.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: RE: Problems adding content to an xml file in exist using orbeon

teppen
I've now tried your suggestions, but I get an error:

org.apache.xmlrpc.XmlRpcException: org.xml.sax.SAXException: Unknown XUpdate element: xu:namespace

I think that's strange since xu:namespace was added in orbeon 2.5. I use 3.7.1.

If I replace <xu:namespace> with <xsl:namespace> I get the same error as before:

org.apache.xmlrpc.XmlRpcException: org.exist.xquery.XPathException: XPST0081: No namespace defined for prefix dm

Tommy

Steve Bayliss wrote
Your xslt output actually looks ok; looks like something to do with how
xmldb-update is handling namespaces.  And I guess the xslt is seeing the
"select" element content purely as text, hence why it carries up the
namespace declaration to the top level rather than recognising the scope.

I think you need to use an <xu:namespace> element, similar to
<xsl:namespace> - see
http://www.orbeon.com/ops/doc/processors-xupdate#d66e228; the syntax should
be as per http://www.w3.org/TR/xslt20/#element-namespace

So I guess something like (I haven't tested this!)

<xu:insert-after select="/dm:Static-Data/dm:Companies/dm:Company[last()]">
  <xu:namespace name="dm" select="'http://www.myns.no/data-model'/>
  <xsl:copy-of select="/dm:Static-Data/dm:Companies/dm:Company"
xmlns:dm="http://www.myns.no/data-model"/>
</xu:insert-after>

(note you will need xmlns:dm on the xsl:copy-of element or xslt won't have a
namespace prefix declaration for dm)

Alternatively I think   <xu:namespace
name="dm">http://www.myns.no/data-model</xu:namespace> should work

And it should also be possible to use the <xsl:namespace> element as an
alternative to this.

If there are still problems with this I would suggest using this approach
but use different namespace prefixes in the "xu:" nodes from the "xsl:"
instructions (eg use
select="/dmx:Static-Data/dmx:Companies/dmx:Company[last()]" in
xu:insert-after and change the xu:namespace name attribute to "dmx").

Steve
Reply | Threaded
Open this post in threaded view
|

RE: RE: RE: Problems adding content to an xml file in exist using orbeon

Steve Bayliss
What about if you try the xsl:namespace approach, but use a different
namespace prefix - ie use "dmx" in the xsl:namespace element and in the
select attribute?

Also would be useful to post your debug output of the xslt processor.

Steve

-----Original Message-----
From: teppen [mailto:[hidden email]]
Sent: 27 October 2009 10:28
To: [hidden email]
Subject: [ops-users] RE: RE: Problems adding content to an xml file in exist
using orbeon



I've now tried your suggestions, but I get an error:

org.apache.xmlrpc.XmlRpcException: org.xml.sax.SAXException: Unknown XUpdate
element: xu:namespace

I think that's strange since xu:namespace was added in orbeon 2.5. I use
3.7.1.

If I replace <xu:namespace> with <xsl:namespace> I get the same error as
before:

org.apache.xmlrpc.XmlRpcException: org.exist.xquery.XPathException:
XPST0081: No namespace defined for prefix dm

Tommy


Steve Bayliss wrote:

>
> Your xslt output actually looks ok; looks like something to do with how
> xmldb-update is handling namespaces.  And I guess the xslt is seeing the
> "select" element content purely as text, hence why it carries up the
> namespace declaration to the top level rather than recognising the scope.
>
> I think you need to use an <xu:namespace> element, similar to
> <xsl:namespace> - see
> http://www.orbeon.com/ops/doc/processors-xupdate#d66e228; the syntax
> should
> be as per http://www.w3.org/TR/xslt20/#element-namespace
>
> So I guess something like (I haven't tested this!)
>
> <xu:insert-after select="/dm:Static-Data/dm:Companies/dm:Company[last()]">
>   <xu:namespace name="dm" select="'http://www.myns.no/data-model'/>
>   <xsl:copy-of select="/dm:Static-Data/dm:Companies/dm:Company"
> xmlns:dm="http://www.myns.no/data-model"/>
> </xu:insert-after>
>
> (note you will need xmlns:dm on the xsl:copy-of element or xslt won't have
> a
> namespace prefix declaration for dm)
>
> Alternatively I think   <xu:namespace
> name="dm">http://www.myns.no/data-model</xu:namespace> should work
>
> And it should also be possible to use the <xsl:namespace> element as an
> alternative to this.
>
> If there are still problems with this I would suggest using this approach
> but use different namespace prefixes in the "xu:" nodes from the "xsl:"
> instructions (eg use
> select="/dmx:Static-Data/dmx:Companies/dmx:Company[last()]" in
> xu:insert-after and change the xu:namespace name attribute to "dmx").
>
> Steve
>
--
View this message in context:
http://n4.nabble.com/Problems-adding-content-to-an-xml-file-in-exist-using-o
rbeon-tp276774p277180.html
Sent from the ObjectWeb OPS - Users mailing list archive at Nabble.com.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: RE: RE: Problems adding content to an xml file in exist using orbeon

teppen
That was it! I tried, as you suggested, a different namespace prefix, and it worked. Thanks Steve!

Tommy

Steve Bayliss wrote
What about if you try the xsl:namespace approach, but use a different
namespace prefix - ie use "dmx" in the xsl:namespace element and in the
select attribute?

Also would be useful to post your debug output of the xslt processor.

Steve
Reply | Threaded
Open this post in threaded view
|

RE: RE: RE: RE: Problems adding content to an xml file in exist using orbeon

Steve Bayliss
That's great!

I wonder now if just using a different namespace prefix alone (ie without
using xsl:namespace) would also work - ie use "dbx:" in your select
attributes and use xmlns:dbx="...." on the xu:insert-after (or even possibly
at the xu:modifications level)...

Steve

-----Original Message-----
From: teppen [mailto:[hidden email]]
Sent: 27 October 2009 11:42
To: [hidden email]
Subject: [ops-users] RE: RE: RE: Problems adding content to an xml file in
exist using orbeon



That was it! I tried, as you suggested, a different namespace prefix, and it
worked. Thanks Steve!

Tommy


Steve Bayliss wrote:
>
> What about if you try the xsl:namespace approach, but use a different
> namespace prefix - ie use "dmx" in the xsl:namespace element and in the
> select attribute?
>
> Also would be useful to post your debug output of the xslt processor.
>
> Steve
>

--
View this message in context:
http://n4.nabble.com/Problems-adding-content-to-an-xml-file-in-exist-using-o
rbeon-tp276774p277208.html
Sent from the ObjectWeb OPS - Users mailing list archive at Nabble.com.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: RE: RE: RE: Problems adding content to an xml file in exist using orbeon

teppen
Yes, it works great just using a different namespace prefix alone. Also at the xu:modification level and even at the xdb:update level. Makes the code look a little bit cleaner. Thanks again!

Tommy

Steve Bayliss wrote
That's great!

I wonder now if just using a different namespace prefix alone (ie without
using xsl:namespace) would also work - ie use "dbx:" in your select
attributes and use xmlns:dbx="...." on the xu:insert-after (or even possibly
at the xu:modifications level)...

Steve
Reply | Threaded
Open this post in threaded view
|

RE: RE: RE: RE: Problems adding content to an xml file in exist using orbeon

teppen
Sorry, it didn't work at the xdb:update level. Must have been some caching there... Anyway, it works if I put it at the xu:modification level.

Tommy

teppen wrote
Yes, it works great just using a different namespace prefix alone. Also at the xu:modification level and even at the xdb:update level. Makes the code look a little bit cleaner. Thanks again!

Tommy

Steve Bayliss wrote
That's great!

I wonder now if just using a different namespace prefix alone (ie without
using xsl:namespace) would also work - ie use "dbx:" in your select
attributes and use xmlns:dbx="...." on the xu:insert-after (or even possibly
at the xu:modifications level)...

Steve