Lasso Soft Inc. > Home

[ xml ]

Method

The [xml] method casts a string or bytes object to the XML data type.

It requires one parameter which is a string (or bytes) containing valid XML data. Optionally the method accepts parameters to set the namespace and document type definition (DTD) of the XML data.

Important: The method requires that the namespaceURI parameter is placed before the data parameter. Additionally the DTD parameter may only be included (after the data parameter) if the namespaceURI parmeter is present.

Note: Initializing a variable using the [xml] method with no parameters assigns it the following XML data: <none xmlns=""/>

  • Syntax
xml( xml_data )

xml( namespace, xml_data )

xml( namespace, xml_data , dtd )
Examples
  • Beginner

To cast a string to XML

Use the [xml] method.

The following example shows the results of casting a particular string to XML using the [xml] method.

Code

var( myString = '<data><item><key>1</key><value>Sat</value></item><item><key>2</key><value>Sun</value></item></data>' )

var( myXML = xml( $myString ) )

'myString is type: '+$myString->type+'\n'
'myXML is type: '+$myXML->type+'\n\n'

$myXml

Result

myString is type: string
myXML is type: xml_element

<data>
  <item>
    <key>1</key>
    <value>Sat</value>
  </item>
  <item>
    <key>2</key>
    <value>Sun</value>
  </item>
</data>

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft