webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

PHP, insert element complex

  • 1.  PHP, insert element complex

    Posted Fri September 05, 2003 01:29 PM

    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.
    ";
    }
    ?>
    -------------


    #Tamino
    #API-Management
    #webMethods


  • 2.  RE: PHP, insert element complex

    Posted Fri September 05, 2003 01:35 PM

    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


    #webMethods
    #Tamino
    #API-Management


  • 3.  RE: PHP, insert element complex

    Posted Fri September 05, 2003 01:54 PM

    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


    #webMethods
    #Tamino
    #API-Management


  • 4.  RE: PHP, insert element complex

    Posted Fri September 05, 2003 02:14 PM

    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


    #Tamino
    #API-Management
    #webMethods


  • 5.  RE: PHP, insert element complex

    Posted Fri September 05, 2003 03:59 PM

    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.]


    #webMethods
    #Tamino
    #API-Management


  • 6.  RE: PHP, insert element complex

    Posted Mon September 08, 2003 10:54 AM

    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.
    ";
    }
    ?>
    ----------------------------------


    #webMethods
    #API-Management
    #Tamino


  • 7.  RE: PHP, insert element complex

    Posted Mon September 08, 2003 01:57 PM

    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.


    #API-Management
    #Tamino
    #webMethods


  • 8.  RE: PHP, insert element complex

    Posted Mon September 08, 2003 02:50 PM

    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


    #webMethods
    #API-Management
    #Tamino


  • 9.  RE: PHP, insert element complex

    Posted Mon September 08, 2003 03:16 PM

    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.


    #webMethods
    #Tamino
    #API-Management