Page 1 of 1

xml editing

Posted: Fri Jan 16, 2009 11:51 pm
by susrisha
Hello all..
I have an xml file of the format :

Code: Select all

 
<?xml version="1.0"?>
<annotations>
    
    <annotation id="3" type="HOTSPOT">
        <time>
            <starttime>7000</starttime>
            <endtime>15000 </endtime>
        </time>
        <params>
            <x>100</x>
            <y>100</y>
            <width>50</width>
            <height>100</height>
            <text>Sample HotSpot</text>
        </params>
    </annotation>   
 
    <annotation id="4" type="HOTSPOT">
        <time>
            <starttime>12000</starttime>
            <endtime>14000 </endtime>
        </time>
        <params>
            <x>220</x>
            <y>70</y>
            <width>50</width>
            <height>80</height>
            <text>Sample HotSpot</text>
        </params>
    </annotation>
 
    <annotation id="1" type="NOTE">
        <time>
            <starttime>13000</starttime>
            <endtime>25000</endtime>
        </time>
        <params>
            <x>170</x>
            <y>160</y>
            <width>100</width>
            <height>40</height>
            <text>Sample Note using xml</text>
        </params>
    </annotation>
        
    <annotation id="2" type="SPEECHBUBBLE">
        <time>
            <starttime>4000</starttime>
            <endtime> 6000</endtime>
        </time>
        <params>
            <x>20</x>
            <y>40</y>
            <width>100</width>
            <height>60</height>
            <text>Sample speech bubble using xml</text>
            <px>180</px>
            <py>80</py>         
        </params>
    </annotation>
    <annotation id="0" type="PAUSE">
        <time>
            <starttime>8000</starttime>
            <endtime>8000</endtime>
            <pausetime>10000</pausetime>
        </time>
        <params>
            <x>20</x>
            <y>40</y>
            <width>100</width>
            <height>60</height>
                
        </params>
    </annotation>
 
    
 
</annotations>
 
There is another file which i got

Code: Select all

 
<document>
<requestHeader video_id="xyz" />
<updateitems>
       <annotation id="3" type="HOTSPOT">
        <time>
            <starttime>7000</starttime>
            <endtime>15000 </endtime>
        </time>
        <params>
            <x>150</x>
            <y>125</y>
            <width>30</width>
            <height>10</height>
            <text>Sample HotSpot</text>
        </params>
    </annotation>
</updateitems>
</document>
 
My problem is how do i replace the parameters of the respective annotation in first page to the annotations in the second xml file.?

Re: xml editing

Posted: Sat Jan 17, 2009 12:20 am
by novice4eva
Take a look at DOM functions in PHP

Re: xml editing

Posted: Sat Jan 17, 2009 12:27 am
by susrisha
Well i suppose that requires a PECL extension but i wanted it to be done on simplexml. is there anyway i can do it?

Re: xml editing

Posted: Sun Jan 18, 2009 10:14 pm
by novice4eva
I have only worked with DOM, which i always thought was a better way, now you've asked it, i did just go through manual and it should be possible, simple xml does provide functions of addChild and addAttribute but i couldn't find anything that directly writes to the XML file itself, i think you will have to re-create the XML text and later add it to a file.

DOM does come bundled with PHP5 and i have no clew regarding its association with PECL 8O

Re: xml editing

Posted: Sun Jan 18, 2009 10:25 pm
by susrisha
i went through the documentation and found the solution. Now i can add the elements and nodes to the xml file. simpleXML is able to do it and i am just saving it as the same file name to overwrite the content and add the given elements. There is also another problem of deleting a particular <annotation> node given the parameter id. I used DOMDOCUMENT class for removing and simpleXML class for adding. Did it finally though. Thanks for the help