0

I am using XML based database to save the records of large scale data in my web application. I know how to fetch all the data or specific data through XML tags in PHP. But I have no idea how I can update the data stored in XML tags using PHP. For instance I want to update the following XML tag by using XQuery from PHP.

<program id="p00547jm">
    <time>
        <startTime>1003394820</startTime>
        <endTime>1003394826</endTime>
        <epochStart>2001-10-18T08:47:00</epochStart>
        <epochEnd>2001-10-25T08:47:00</epochEnd>
    </time>
    <completeTitle>in_our_time:_democracy</completeTitle>
    <mediaType>audio</mediaType>

I am using following XQuery to update the value of 1 particular XML tag:

$query='for $x in doc("coursework")/bbcPrograms/program 
 where $x/completeTitle="'.$single_edit_program_title_hidden.'" 
 and $x/mediaType="'.$single_edit_program_type_hidden.'" and 
 $x/masterBrand="'.$single_edit_masterbrand_hidden.'" and 
 $x/service="'.$single_edit_service_hidden.'"  

 return update value $x/completeTitle[.="'.$single_edit_program_title_hidden.'"] with "'.$single_edit_program_title.'"';

It works correctly when we want to update 1 particular XML tag value. Now I want to make this XQuery work for updating tags values of multiple XML tags. Just as we do normally in SQL. SET id='abc' AND name = 'xyz'...

Please help me how this Xquery can work for multiple tags values update.

Community
  • 1
  • 1
Formanite
  • 1
  • 1
  • Using XQuery you can't. But there is XQuery Update, which is a standard exactly defined for this. Most XML databases should support it, otherwise there might be some other implementation-specific update language. You will have to tell us which database you use in order for us to help you. – dirkk May 09 '15 at 16:10
  • hey, I am using this Xquery to update one XML tag value: $query='for $x in doc("coursework")/bbcPrograms/program where $x/completeTitle="'.$single_edit_program_title_hidden.'" and $x/mediaType="'.$single_edit_program_type_hidden.'" and $x/masterBrand="'.$single_edit_masterbrand_hidden.'" and $x/service="'.$single_edit_service_hidden.'" return update value $x/completeTitle[.="'.$single_edit_program_title_hidden.'"] with "'.$single_edit_program_title.'" '; – Formanite May 10 '15 at 09:27
  • 1
    Please edit your question, code in comments in basically unreadable. Also, you still haven't told us which database you use. – dirkk May 10 '15 at 15:30

0 Answers0