PHP, insert element complex

Hello!

I just want to add element complex “address” into my collection “Hospital” and doctype “patient”. Unfortunately I got the following error:

----
Tamino Error 7730: (cvc-model-group.1):invalid end of sequence (XQuery Update Request processing) (Line 0, Column 0: [element “address” in element “patient”])
----

In my database I have got the data:



Atkins
Paul

Male
1964

Harbour Close
23
Portsmouth
PO2056HAR

Professional Diver



I just want to have the following data:



Atkins
Paul

Male
1964

Harbour Close
23
Portsmouth
PO2056HAR


Kwiatowa
5
Warsaw
00-950

Professional Diver



How should I fix my source code?

In advance, thanks a lot!

best regards,
Dariusz Baumann


PS.

Here is code:
-------------
<?php

header("Content-Type: text/html; charset=UTF-8");

include "TaminoAPI.php";
include "TaminoHelperFunctions.php";

$PC_HOST = "localhost";
$PC_PORT = "80";
$PC_DATABASE = "mydb";
$PC_COLLECTION = "Hospital";
$PC_DOCTYPE = "patient";
$PC_ENCODING = "UTF-8";
$PC_USERNAME = "";
$PC_PASSWORD = "";

$tamino = &new TaminoAPI($PC_HOST,
$PC_PORT,
$PC_DATABASE,
$PC_USERNAME,
$PC_PASSWORD);

$tamino->setCollection($PC_COLLECTION);

$tamino->setEncoding($PC_ENCODING);

$surname = "Atkins";

$xquery = "update for \$a in input()/$PC_DOCTYPE ".
"where \$a/name/surname = \"$surname\" ".
"do ".
"(".
"insert into \$a ".
"insert Kwiatowa into \$a ".
"insert 5 into \$a ".
"insert Warsaw \$a ".
"insert 00-950 \$a ".
"insert into \$a ".
")";

if (!($tamino->xquery($xquery)))
{
echo "ERROR
";
thfPrintError($tamino);
}
else
{
echo "OK.
";
}
?>
-------------

Sorry.

This is corrent data which I just want to have:



Atkins
Paul

Male
1964

Harbour Close
23
Portsmouth
PO2056HAR


Kwiatowa
5
Warsaw
00-950

Professional Diver

Hi!

I just modified the value of variable $xquery in the following way:


$xquery = "update for $a in input()/$PC_DOCTYPE ".
"where $a/name/surname = "$surname" ".
"do insert ".
“”.
“Kwiatowa”.
“5”.
“Warsaw”.
“00-950”.
" into $a ";



Unfortunately I got the same errror:

-----
Tamino Error 7730: (cvc-model-group.1):invalid end of sequence (XQuery Update Request processing) (Line 0, Column 0: [element “address” in element “patient”])
-----

Please help!

In advance, thanks!

best regards,
Dariusz Baumann

Hi!

I have been still modifing my php code to get it work. I tried in this way:


$xquery = "update insert ".
“”.
“Kwiatowa”.
“5”.
“Warsaw”.
“00-950”.
“”.
“into input()/$PC_DOCTYPE [name/surname="$surname"]”;


Unfortunately, the same error appears:

------
Tamino Error 7730: (cvc-model-group.1):invalid end of sequence (XQuery Update Request processing) (Line 0, Column 0: [element “address” in element “patient”])
------

What can I do, to fix it?

best regards,
Dariusz Baumann

Hi Dariusz,

The 7730 error comes from the fact that the modified document as a result of the xquery-update is no longer valid againest the schema. Firstly you need to change the schema and change the cardinality of address by adding maxOccurs=“unbounded” for the address element reference in the patient element sequence. Then the following xquery-update works for me:

update for $a in input()/patient
where $a/name/surname = “Atkins”
do insert

Kwiatowa
5
Warsaw
00-950

following $a/address


I also noted that there is something in the Tamino documentation about this, have a look at …/documentation/xquery/xq-update.htm#xq-update-conform under the Tamino installation.

Hope this helps.

Stuart Fyffe-Collins
Software AG (UK) Ltd.

[This message was edited by Stuart Fyffe-Collins on 05 Sep 2003 at 14:52.]

Hi Stuart!

I tried like you adviced but I have got a problem. :frowning:

I modified schema, deleted data and insert new data, so now my data in Tamino is like the following:

----------------------------------


Atkins
Paul

Male
1964

Harbour Close
23
Portsmouth
PO2056HAR


GreenStreet
10
Berlin
AB900B

Professional Diver


----------------------------------

After executing sample script php, I got in Tamino the following data:

----------------------------------


Atkins
Paul

Male
1964

Harbour Close
23
Portsmouth
PO2056HAR


Kwiatowa
5
Warsaw
00-950


GreenStreet
10
Berlin
AB900B


Kwiatowa
5
Warsaw
00-950

Professional Diver


----------------------------------

So the php script added two nodes, and now I have got four addresses. :frowning:

How should I modify this php script?

In advance, thanks a lot!

best regards,
Dariusz Baumann

PS.

Here is php script:

----------------------------------
<?php

header("Content-Type: text/html; charset=UTF-8");

include "TaminoAPI.php";
include "TaminoHelperFunctions.php";

$PC_HOST = "localhost";
$PC_PORT = "80";
$PC_DATABASE = "mydb";
$PC_COLLECTION = "Hospital";
$PC_DOCTYPE = "patient";
$PC_ENCODING = "UTF-8";
$PC_USERNAME = "";
$PC_PASSWORD = "";

$tamino = &new TaminoAPI($PC_HOST,
$PC_PORT,
$PC_DATABASE,
$PC_USERNAME,
$PC_PASSWORD);

$tamino->setCollection($PC_COLLECTION);

$tamino->setEncoding($PC_ENCODING);

$surname = "Atkins";

$xquery = "update for \$a in input()/$PC_DOCTYPE ".
"where \$a/name/surname = \"$surname\" ".
"do insert ".
" ".
"Kwiatowa ".
"5 ".
"Warsaw ".
"00-950 ".
" ".
"following \$a/address ";

if (!($tamino->xquery($xquery)))
{
echo "ERROR
";
thfPrintError($tamino);
}
else
{
echo "OK.
";
}
?>
----------------------------------

Hi Dariusz,

Sorry(!) of course the ‘following $a/address’ will insert after each address element so if there are two of them you will get four after the insert. So to fix this you can insert following the last address with:

update for $a in input()/patient
where $a/name/surname = “Atkins”
do insert

Kwiatowa
5
Warsaw
00-950

following $a/address[last()]

Bye for now,

Stuart Fyffe-Collins
Software AG (UK) Ltd.

Hi Stuart!

Unfortunately, function last() (following $a/address[last()]) does not work if there is no node “address”. :frowning:

Example data stored in Tamino is:

-----------------------


Atkins
Paul

Male
1964
Professional Diver


-----------------------

Element complex “address” is defined like this:
minOccurs=0
maxOccurs=unbounded

So, it is possible that the source data will not include “address” element.
So how then should I insert new element “address” ?

Thanks a lot for support, Stuart!

best regards,
Dariusz Baumann

Hi Dariusz,

Below is one solution - maybe there is a more elegant way to do this - but this works. It checks for the existance of address elements, if not exists then the insert of the address goes after the born element otherwise after the last address element.

update for $a in input()/patient
where $a/name/surname = “Atkins”
do insert

Kwiatowa
5
Warsaw
00-950

following (
(let $e := $a/address[last()] where count($a/address) > 0 return $e),
(let $e := $a/born where count($a/address) = 0 return $e)
)



Could someone with deeper insight into the Tamino XQuery implementation comment?

Bye for now.

Stuart Fyffe-Collins
Software AG (UK) Ltd.