Whatever message this page gives is out now! Go check it out!
| Function | Use |
Determines the number of child elements in an element, that is, the number of elements in an element's XmlChildren array. | |
Determines whether an element has any elements in its XmlChildren array. | |
Determines the number of attributes in an element's XmlAttributes structure. | |
Determines whether an element has any attributes in its XmlAttributes structure.Returns True if the specified structure, including the XML document object or an element, exists and is empty. | |
Gets an array or list with the names of all of the attributes in an element's XmlAttributes structure. Returns the names of the children of an XML element. | |
Adds a new element at a specific location in an element's XmlChildren array. | |
Adds a new element at the end or beginning of an element's XmlChildren array. | |
Swaps the children in the XmlChildren array at the specified position. | |
Sets a range of entries in an XmlChildren array to equal the contents of a specified element structure. Each entry in the array range is a copy of the structure. Can be used to set a single element by specifying the same index as the beginning and end of the range. | |
Deletes a specific element from an element's XmlChildren array. | |
Deletes all child elements from an element's XmlChildren array. | |
Deletes a selected attribute from an element's XMLAttributes structure.Deletes all children with a specific element name from an element's XmlChildren array.Deletes all attributes of an element.Deletes all children of an element.Deletes a selected property value. | |
Deletes all attributes from an element's XMLAttributes structure. | |
Copies an XML document object, element, or node structure. | |
Returns True for the XmlChildren array. Returns false if you specify an element name, such as mydoc.XmlRoot.name, even if multiple name elements exist in XmlRoot. | |
Returns False for XML document objects, elements, and nodes. Returns True for XmlAttributes structures. | |
Returns the specified structure, including XML document objects, elements, nodes, and XmlAttributes structures. | |
Appends a document fragment XML document object to another XML document object. | |
Adds a new entry to an XmlAttributes structure. | |
Sets or replaces the value of a document object property such as XmlName, or of a specified attribute in an XmlAttributes structure. |
| Array function | Result |
IsArray(elemPath.elemName) | Always returns False. |
ArrayClear(elemPath.elemName) | Removes all the elements with name elemName from the elemPath element. |
ArrayLen(elemPath.elemName) | Returns the number of elements named elemName in the elemPath element. |
ArrayDeleteAt(elemPath.elemName, n) | Deletes the nth child named elemName from the elemPath element. |
ArrayIsEmpty(elemPath.elemName) | Always returns False. |
ArrayToList(elemPath.elemName, n) | Returns a comma-separated list of all the XmlText properties of all the children of elemPath named elemName. |
| Type | Using a function | Using an assignment statement | ||||||||
Attribute |
| StructInsert(xmlElemPath.XmlAttributes, "key", "value") |
| xmlElemPath.XmlAttributes.key ="value" | xmlElemPath.XmlAttributes["key"]="value" | |||||
Child element | To append:
To insert:
| ArrayAppend(xmlElempath.XmlChildren,newElem) | ArrayInsertAt(xmlElempath.XmlChildren, position, newElem) | To append:
(where newChildName must be the same as newElem.XmlName and cannot be an indexed name such as name[3]) | xmlElemPath.XmlChildren[i] =newElem | xmlElemPath.newChildName =newElem |
| Type | Using a function | Using an assignment statement | ||||||
Property |
| StructDelete(xmlElemPath, propertyName) |
| xmlElemPath.propertyName="" | ||||
Attribute | All attributes:
A specific attribute:
| StructDelete(xmlElemPath, XmlAttributes) | StructDelete(xmlElemPath.XmlAttributes,"attributeName") | Not available | ||||
Child element | All children of an element:
or
All children with a specific name:
A specific child:ArrayDeleteAt(xmlElemPath.XmlChildren,position) ArrayDeleteAt(xmlElemPath.elemName,position) | StructDelete(xmlElemPath, "XmlChildren") | ArrayClear(xmlElemPath.XmlChildren) | StructDelete(xmlElementpath,"elemName") ArrayClear(xmlElemPath.elemName) | Not available |
| Type | Using a function | Using an assignment statement | ||||||||||
Property |
| StructUpdate(xmlElemPath,"propertyName", "value") |
| xmlElemPath.propertyName ="value" | xmlElemPath["propertyName"] ="value" | |||||||
Attribute |
| StructUpdate(xmlElemPath.XmlAttributes,"attributeName", "value") |
| xmlElemPath.XmlAttributes.attributeName="value" | xmlElemPath.XmlAttributes["attributeName"] = "value" | |||||||
Child element(replace) |
(use the same value for both index entries to change one element) | ArraySet(xmlElemPath.XmlChildren, index,index, newElement) | Replace first or only child named elementName:
Replace a specific child named elementName:
or
| parentElemPath.elementName =newElement | parentElemPath["elementName"]= newElement | parentElemPath.elementName[index] = newElement | parentElemPath["elementName"][index] = newElement |
function NodeCount (xmlElement, nodeName) { nodesFound = 0; for (i = 1; i LTE ArrayLen(xmlElement.XmlChildren); i = i+1) { if (xmlElement.XmlChildren[i].XmlName IS nodeName) nodesFound = nodesFound + 1; } return nodesFound; } </cfscript> |
Nodes Found: #NodeCount(mydoc.employee, "name")# </cfoutput> |
<cfset nameIndex = XmlChildPos(mydoc.employee, "name", 2)> |
XmlElemNew(docObject, elementName) |
"phoneNumber"))> |
"department"))> |
<cfset ArrayInsertAt(mydoc.employee.name, 2, XmlElemNew(mydoc, "PhoneNumber")> |
nameIndex = XmlChildPos(mydoc.employee, "name", 1); ArrayInsertAt(mydoc.employee.XmlChildren, nameIndex + 1, XmlElemNew(mydoc, "name")); </cfscript> |
mydoc.supplies.XmlChildren[1] = XmlElemNew(mydoc, "http://www.foo.com/Products", "Prod:soap"); mydoc.supplies.XmlChildren[2] = XmlElemNew(mydoc, "Prod:shampoo"); </cfscript> |
<cfset mydoc.employee.XmlChildren[9] = XmlElemNew(mydoc, "name")> |
<cfset mydoc.employee.name[1].phoneNumber = XmlElemNew(mydoc, "phoneNumber")> |
<cfset mydoc.employee.name[3] = XmlElemNew(mydoc, "name")> |
<cfset mydoc.employee.XmlChilren[3] = XmlElemNew(mydoc, "name")> |
<cfset mydoc.employee.name[2].phoneNumber = mydoc.employee.name[1].phoneNumber> |
<cfset mydoc.employee.name[2].telephone = mydoc.employee.name[1].phoneNumber> |
<cfset ArrayDeleteAt(mydoc.employee.XmlChildren, 2)> |
<cfset StructDelete(mydoc.employee.name[2], "phoneNumber")> |
<cfset ArrayDeleteAt(mydoc.employee.name, 2)> |
<cfset ArrayDeleteAt(mydoc.employee.XmlChildren, idx)> |
<cfset ArrayClear(mydoc.employee.name)> |
<cfset ArrayClear(mydoc.employee.name[2].XmlChildren)> |
<cfset StructInsert(mydoc.employee.name[2].XmlAttributes, "Status", "Inactive")> |
<cfset mydoc.employee.name[2].XmlAttributes.Status="Active"> |
<cfset StructDelete(mydoc.employee.name[1].XmlAttributes, "Status")> |
MyCompany Documentation Department"> |
<cfset StructDelete(mydoc.employee, "XmlComment")> |
<cfset mydoc.employee.XmlChildren[1] = XmlElemNew(mydoc, "Organization")> |
<cfset mydoc.employee.name[2].phoneNumber=mydoc.employee.name[1].phoneNumber> |
<cfset StructDelete(mydoc.employee.name[1], "phoneNumber")> |
<cffile action="read" file="C:\CFusion\wwwroot\myexamples\employees.xml" variable="myxml"> <cfset mydoc = XmlParse(myxml)> <!--- get an array of employees ---> <cfset emp = mydoc.employee.XmlChildren> <cfset size = ArrayLen(emp)> <cfoutput> Number of employees = #size# <br> </cfoutput> <br> <!--- create a query object with the employee data ---> <cfset myquery = QueryNew("fname, lname") > <cfset temp = QueryAddRow(myquery, #size#)> <cfloop index="i" from = "1" to = #size#> <cfset temp = QuerySetCell(myquery, "fname", #mydoc.employee.name[i].first.XmlText#, #i#)> <cfset temp = QuerySetCell(myquery, "lname", #mydoc.employee.name[i].last.XmlText#, #i#)> </cfloop> <!--- Dump the query object ---> Contents of the myquery Query object: <br> <cfdump var=#myquery#> <br><br> <!--- Select entries with the last name starting with A and dump the result ---> <cfquery name="ImqTest" dbType="query"> SELECT lname, fname FROM myquery WHERE lname LIKE 'A%' </cfquery> <cfdump var=#imqtest#> |
<cfquery name="myQuery" datasource="cfdocexamples"> SELECT FirstName, LastName FROM employee </cfquery> <!--- Create an XML document object containing the data ---> <cfxml variable="mydoc"> <employee> <cfoutput query="myQuery"> <name> <first>#FirstName#</first> <last>#LastName#</last> </name> </cfoutput> </employee> </cfxml> <!--- dump the resulting XML document object ---> <cfdump var=#mydoc#> <!--- Write the XML to a file ---> \\x output=#toString(mydoc)#> |