www.icetips.com  Icetips Utilities Documentation 1/25/2016    

String Class:  FormatXML

Previous  Top  Next  


Prototype: (STRING pXML, BYTE pIndentSpaces=2),STRING

 

pXMLXML string to format. 
pIndentSpacesNumber of spaces for each indentation.  Defaults to 2

 

ReturnsString with formatted xml

 

This method does some basic formatting to xml strings to make them more human readable.  Note that this is ONLY designed to work on non-formatted xml streams.  If there are spaces between between the end and begin tags the formatting may be thrown off. 

See the example below.  Note that the indentation is done with spaces and the resulting XML is only meant for human reading, not to be passed to xml parsers/readers as the additional spaces will bloat the string/file considerably! 

 

As a side note, you can load XML files into Clarion and validate them.  When you load a XML file into Clarion, a new menu appears that has some options for XML files.

 

StringClass_XML_Menu_In_C10

 

Example:

 

PROGRAM

INCLUDE('ITUtilityClass.inc'),ONCE

MAP

END

S   CSTRING(2000)

ITS ITStringClass

CODE

S = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope ' &|

     'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' &|

     'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' &|

     'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' &|

     '<soap:Body>' &|

     '<TermOfPayment_GetAllResponse xmlns="http://thedomain.com">' &|

     '<TermOfPayment_GetAllResult>' &|

     '<TermOfPaymentHandle><Id>1</Id></TermOfPaymentHandle>' &|

     '<TermOfPaymentHandle><Id>2</Id></TermOfPaymentHandle>' &|

     '<TermOfPaymentHandle><Id>4</Id></TermOfPaymentHandle>' &|

     '<TermOfPaymentHandle><Id>5</Id></TermOfPaymentHandle>' &|

     '</TermOfPayment_GetAllResult>' &|

     '</TermOfPayment_GetAllResponse>' &|

     '</soap:Body></soap:Envelope>'

S = ITS.FormatXML(S,2)

ITS.WriteStringToFile('test.xml',S)

 

This would result in test.xml file that looks like this:

 

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>

   <TermOfPayment_GetAllResponse xmlns="http://thedomain.com">

     <TermOfPayment_GetAllResult>

       <TermOfPaymentHandle>

         <Id>1</Id>

       </TermOfPaymentHandle>

       <TermOfPaymentHandle>

         <Id>2</Id>

       </TermOfPaymentHandle>

       <TermOfPaymentHandle>

         <Id>4</Id>

       </TermOfPaymentHandle>

       <TermOfPaymentHandle>

         <Id>5</Id>

       </TermOfPaymentHandle>

     </TermOfPayment_GetAllResult>

   </TermOfPayment_GetAllResponse>

</soap:Body>

</soap:Envelope>

 

See also:

WriteStringToFile

 



Direct link to this page: http://www.icetips.com/manuals/utilities/formatxml_stringclass.htm