wwXML::ObjectToXML

This high level method converts a live object reference to XML. All variables are converted to text and stored.

Optionally can nest objects using the lRecurseObjects property flag. You can also create an optional DTD for the object with the lCreateDataStructure property, but only if objects are not recursed multiple levels.

You can set the document root name (xdoc in the document) with the cDocRoot.

o.ObjectToXml(loObject, lcName, lnIndent, llNoHeader)

Return Value

XML string

Parameters

loObject
Object reference to represent as XML

lcName
Optional - Name of attribute used for the <object> element.

lnIndent
Optional - Starting indentation level. Default 0.

llNoHeader
Optional - Create XML document without XML header. Default: .F.

Example

*** DTD Example
oXML = CREATE("wwXML")

*** Load Business object
oItem = CREATEOBJECT("cItem")
? oITem.getitembysku("WCONNECT")

oXML.nCreateDataStructure = 1  && Schema
lcXML = oXML.ObjectToXML(oItem.oData)
ShowXML(lcXML)



<?xml version="1.0"?>
<!DOCTYPE xdoc [
<!ELEMENT xdoc (class)>
<!ELEMENT class (categories,colors,cost,descript,emailto,expected,image,keywords,ldescript,list1,list2,mfr,noweb,onorder,order,physical,pk,price,regtext,savemail,sizes,sku,special,stock,storepk,url,weight,xml)>
<!ELEMENT categories (#PCDATA)>
<!ATTLIST categories type CDATA #FIXED "string" >
<!ELEMENT colors (#PCDATA)>
<!ATTLIST colors type CDATA #FIXED "string" >
<!ELEMENT cost (#PCDATA)>
<!ATTLIST cost type CDATA #FIXED "float" >
<!ELEMENT descript (#PCDATA)>
<!ATTLIST descript type CDATA #FIXED "string" >
<!ELEMENT emailto (#PCDATA)>
<!ATTLIST emailto type CDATA #FIXED "string" >
<!ELEMENT expected (#PCDATA)>
<!ATTLIST expected type CDATA #FIXED "date" >
<!ELEMENT image (#PCDATA)>
<!ATTLIST image type CDATA #FIXED "string" >
<!ELEMENT keywords (#PCDATA)>
<!ATTLIST keywords type CDATA #FIXED "string" >
<!ELEMENT list1 (#PCDATA)>
<!ATTLIST list1 type CDATA #FIXED "string" >
<!ELEMENT list2 (#PCDATA)>
<!ATTLIST list2 type CDATA #FIXED "string" >
<!ELEMENT mfr (#PCDATA)>
<!ATTLIST mfr type CDATA #FIXED "string" >
<!ELEMENT noweb (#PCDATA)>
<!ATTLIST noweb type CDATA #FIXED "boolean" >
<!ELEMENT onorder (#PCDATA)>
<!ATTLIST onorder type CDATA #FIXED "float" >
<!ELEMENT order (#PCDATA)>
<!ATTLIST order type CDATA #FIXED "float" >
<!ELEMENT physical (#PCDATA)>
<!ATTLIST physical type CDATA #FIXED "boolean" >
<!ELEMENT pk (#PCDATA)>
<!ATTLIST pk type CDATA #FIXED "float" >
<!ELEMENT price (#PCDATA)>
<!ATTLIST price type CDATA #FIXED "float" >
<!ELEMENT savemail (#PCDATA)>
<!ATTLIST savemail type CDATA #FIXED "string" >
<!ELEMENT sizes (#PCDATA)>
<!ATTLIST sizes type CDATA #FIXED "string" >
<!ELEMENT sku (#PCDATA)>
<!ATTLIST sku type CDATA #FIXED "string" >
<!ELEMENT special (#PCDATA)>
<!ATTLIST special type CDATA #FIXED "float" >
<!ELEMENT stock (#PCDATA)>
<!ATTLIST stock type CDATA #FIXED "float" >
<!ELEMENT storepk (#PCDATA)>
<!ATTLIST storepk type CDATA #FIXED "float" >
<!ELEMENT url (#PCDATA)>
<!ATTLIST url type CDATA #FIXED "string" >
<!ELEMENT weight (#PCDATA)>
<!ATTLIST weight type CDATA #FIXED "float" >
<!ELEMENT xml (#PCDATA)>
<!ATTLIST xml type CDATA #FIXED "string" >

]>
<xdoc>
	<class>
		<categories><![CDATA[West Wind Products
Web Tools
Web Connection]]></categories>
		<colors></colors>
		<cost>0</cost>
		<descript>West Wind Web Connection 3.15</descript>
		<emailto></emailto>
		<expected></expected>
		<image>wconnect.gif</image>
		<keywords></keywords>
		<savemail></savemail>
		<sizes></sizes>
		<sku>WCONNECT</sku>
		<special>0</special>
		<stock>0</stock>
		<storepk>0</storepk>
		<url>http://www.west-wind.com/webconnection/</url>
		<weight>0</weight>
		<xml></xml>
	</class>
</xdoc>


*** Schema Example oXML = CREATEOBJECT('wwXML') *** Load Business object oItem = CREATEOBJECT("cItem") ? oITem.getitembysku("WCONNECT") oXML.nCreateDataStructure = 1 && Schema lcXML = oXML.ObjectToXML(oItem.oData) ShowXML(lcXML) <?xml version="1.0"?> <xdoc> <Schema name="Test" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <ElementType name="class" content="eltOnly" model="closed" order="many"> <element type="categories"/> <element type="colors"/> <element type="cost"/> <element type="descript"/> <element type="emailto"/> <element type="expected"/> <element type="image"/> <element type="keywords"/> <element type="list1"/> <element type="list2"/> <element type="mfr"/> <element type="noweb"/> <element type="onorder"/> <element type="order"/> <element type="physical"/> <element type="pk"/> <element type="price"/> <element type="savemail"/> <element type="sizes"/> <element type="sku"/> <element type="special"/> <element type="stock"/> <element type="storepk"/> <element type="url"/> <element type="weight"/> <element type="xml"/> </ElementType> <ElementType name="categories" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="colors" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="cost" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="descript" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="emailto" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="expected" content="textOnly" model="closed" dt:type="date"> <AttributeType name="type"/> <attribute type="type" default="date"/> </ElementType> <ElementType name="image" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="keywords" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="list1" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="list2" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="mfr" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="noweb" content="textOnly" model="closed" dt:type="boolean"> <AttributeType name="type"/> <attribute type="type" default="boolean"/> </ElementType> <ElementType name="onorder" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="order" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="physical" content="textOnly" model="closed" dt:type="boolean"> <AttributeType name="type"/> <attribute type="type" default="boolean"/> </ElementType> <ElementType name="pk" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="price" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="savemail" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="sizes" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="sku" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="special" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="stock" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="storepk" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="url" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> <ElementType name="weight" content="textOnly" model="closed" dt:type="float"> <AttributeType name="type"/> <attribute type="type" default="float"/> </ElementType> <ElementType name="xml" content="textOnly" model="closed" dt:type="string"> <AttributeType name="type"/> <attribute type="type" default="string"/> </ElementType> </Schema> <class xmlns="x-schema:#Test"> <categories><![CDATA[West Wind Products Web Tools Web Connection]]></categories> <colors></colors> <cost>0</cost> <descript>West Wind Web Connection 3.15</descript> <emailto></emailto> <expected></expected> <image>wconnect.gif</image> <keywords></keywords> <savemail></savemail> <sizes></sizes> <sku>WCONNECT</sku> <special>0</special> <stock>0</stock> <storepk>0</storepk> <url>http://www.west-wind.com/webconnection/</url> <weight>0</weight> <xml></xml> </class> </xdoc>

See also:

Class wwXML (High Level Methods)

© West Wind Technologies, 2023 • Updated: 07/28/00
Comment or report problem with topic