Convert CkXml created by Chilkat to string PHP

101 views Asked by At

I am using chilkat_9_5_0 extension to create XML and I am facing an issue where in order to get the xml as string, I need to write it into a file then load the file as a string.

$xml = new CkXml();
              $xml->put_Tag('Invoice');
              $xml->AddAttribute('xmlns','urn:oasis:names:specification:ubl:schema:xsd:Invoice-2');
              $xml->AddAttribute('xmlns:cac','urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2');
              $xml->AddAttribute('xmlns:cbc','urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2');
              $xml->AddAttribute('xmlns:ext','urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2');

Writing it to a file:

         $success = $sbXml->WriteFile('C:/Apps/SignedXML/signedXmlResult1.xml','utf-8',false);
         $success = $gen->CreateXmlDSigSb($sbXml);
              if ($success = true) {

                  //Corrected Entry of Qr Id with single Quote in XML
                  $path_to_file = 'C:/zatcaenvoicesdk28102021/Apps/SignedXML/signedXmlResult1.xml';
                  $file_contents = file_get_contents($path_to_file); 
                  file_put_contents($path_to_file, $file_contents); 

              echo '<p>XML UBL 2.1 with Digital Signature Successfully added..</p>';

              }

Extension link:

https://www.example-code.com/phpExt/xml.asp

I would really appreciate your support if you know how to convert CkXml to string without writing it to a file, so I can store it in database.

1

There are 1 answers

0
abdulrahman albeladi On BEST ANSWER

I found this solution and it is now working with me:

          $string= $sbXml->GetAsString();