xml - Append at a specific position using PHP files -


i trying add <?xml-stylesheet type='text/xsl' href='soap.xslt'?> after <?xml version="1.0" encoding="utf-8"?> xml file, in fact soap response replacing data found after <?xml version="1.0" encoding="utf-8"?> link stylesheet.
here's part of code client.php writes soap response file , appends part want.

<?php  if(isset($_post['search_input'])) { try {     $input = $_post['search_input'];      $wsdl = "http://localhost/webservice/uddi/90210store.wsdl";      //$options = array('cache_wsdl'=>wsdl_cache_none, 'features'=>soap_single_element_arrays);      //$client = new soapclient($wsdl, $options);      $debugoption = array('trace'=>true, 'cache_wsdl'=>wsdl_cache_none, 'features'=>soap_single_element_arrays);     $client = new soapclient($wsdl, $debugoption);      $response = $client->viewdressperprice($input);       $soaprequest = "<strong>request:</strong><br/>" . htmlspecialchars($client->__getlastrequest()) . "<br/>";     $soapresponse = htmlspecialchars($client->__getlastresponse());      echo $soapresponse;      $file = 'soap.xml';      file_put_contents($file, $soapresponse);      $file2 = fopen($file, "r+");     fseek($file2, 64, seek_set); //maybe offset not correct     fwrite($file2, "<?xml-stylesheet type='text/xsl' href='soap.xslt'?>");     fclose($file2);      //rest of code ?> 

here's content of xml file:

<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type='text/xsl' href='soap.xslt'> schemas.xmlsoap.org/soap/envelope/" //where not appending correctly xmlns:ns1="http://www.shehzad.edu/webservice"> <soap-env:body>   <ns1:result>      <ns1:dressperprice>         <ns1:name>dress 2</ns1:name>         <ns1:price>20</ns1:price>         <ns1:image>2.jpeg</ns1:image>      </ns1:dressperprice>      <ns1:dressperprice>         <ns1:name>dress 9</ns1:name>         <ns1:price>20</ns1:price>         <ns1:image>3.jpeg</ns1:image>      </ns1:dressperprice>      <ns1:dressperprice>         <ns1:name>dress 10</ns1:name>         <ns1:price>20</ns1:price>         <ns1:image>0905c58a0179_1.jpeg</ns1:image>      </ns1:dressperprice>      <ns1:dressperprice>         <ns1:name>dress 11</ns1:name>         <ns1:price>20</ns1:price>         <ns1:image>0905c58a0179_1.jpeg</ns1:image>      </ns1:dressperprice>      <ns1:dressperprice>         <ns1:name>dress 12</ns1:name>         <ns1:price>20</ns1:price>         <ns1:image>0905c58a0179_1.jpeg</ns1:image>      </ns1:dressperprice>   </ns1:result> </soap-env:body> </soap-env:envelope> 

it seems cutting , adding instead of correctly appending it. appreciated. thanks.

use domdocument manipulate xml document e.g.

$doc = new domdocument(); $doc->load('file.xml'); $doc->insertbefore($doc->createprocessinginstruction('xml-stylesheet', "type='text/xsl' href='soap.xslt'"), $doc->documentelement); $doc->save('file.xml'); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -