Why do you write into XML file? You can make XML directly from PHP
here is really good example how to do that:
http://code.google.com/support/bin/answer.py?answer=65622

On Jun 26, 9:47 pm, Ivan <[email protected]> wrote:
> Hi guys I am trying to create an xml file but i am getting awkward
> results on the xml file. Firstly the else{} clause does create the xml
> file but whenever this code gets executed again it doesn not seem to
> write the xml properly. I am trying to achieve a quick write to the
> xml file at top by searching for "markers" and replacing it with the
> new element. See code.
>
> What i am trying to achieve is basically this: if i execute the code 2
> times
>
> -------------------------------------
> <markers>
> <marker a="" ..../>
> <marker a="" ..../>
> </markers>
> ---------------------------------------
>
> I am actualy getting this:
>
> ----------------------------------
> <markers>
> <marker a="" ..../>
> </markers>
>
> <markers>
> <marker a="" ..../>
> <marker a="" ..../>
> </markers>
>
> -------------------------------
>
> here is my code :
>
>      /****Write to XML
> FILE******************************************************************************/
>
>            $cxmlfile = '/home/user/public_html/files/
> english/'.strtolower($countryname).'_'.strtolower($ucategory).'.xml';
>
>            if (file_exists($cxmlfile)) {
>
>            $file_handle = fopen($cxmlfile,'r+');
>
>            $xmlfilecontents = fread($file_handle,filesize($cxmlfile));
>
>            $node = '<markers>'."\n".'<marker placename="'.
> $uplacename.'" countrycode="'.$ucountrycode.'" category="'.
> $ucategory.'" address="'. $uaddress.'" phone="'.$uphone.'" username="'.
> $uusername.'" lat="'.$ulat.' " lng="'. $ulng. '" 
> image="http://www.mysite.com/images/'.strtolower($ucountrycode).'/'.strtolower($uca..."
> video="'.$uvideo.'" icon="http://www.mysite.com/images/icons/'.
> $uicon.'" url ="" html="'.$uhtml.'"  />';
>
>            $content=str_replace('<markers>',$node,$xmlfilecontents);
>
>            fwrite($file_handle,$content);
>            fclose($file_handle);
>
>            } else {
>
>            $file_handle = fopen($cxmlfile,'w+');
>
>            $nodefile = '<markers><marker placename="'.$uplacename.'"
> countrycode="'.$ucountrycode.'" category="'.$ucategory.'" address="'.
> $uaddress.'" phone="'.$uphone.'" username="'.$uusername.'" lat="'.
> $ulat.' " lng="'. $ulng. '" image="http://www.mysite.com/
> images/'.strtolower($ucountrycode).'/'.strtolower($ucategory).'/'.
> $uimage.'" video="'.$uvideo.'" icon="http://www.mysite.com/images/
> icons/'.$uicon.'" url ="" html="'.$uhtml.'"  /></markers>';
>
>            /*$content=str_replace('<markers>',$nodefile,$cmlfile);*/
>
>            fwrite($file_handle,$nodefile);
>            fclose($file_handle);
>            }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to