Hi Tom (Schreck)
Your code - for retrieving specific elements and their children - looks
good. The only alternative I can suggest is to use one of the existing
custom tags (like soXML or the XML Toolkit) although these won't give you
any performance advantages. I've copied below the way the code for doing
this with the Toolkit tags:
<!--- create an XML datasource from your information --->
<cf_xmldatasource name = "ds_ElementTemplates">
<ElementTemplates>
<TextBox>
<elementType>TextBox</elementType>
<elementName>This is the element Name</elementName>
<elementLabel/>
<elementLabelClass/>
<elementClass/>
<elementPosition/>
<elementSize/>
<elementMaxLength/>
<DefaultValue/>
<xslMember/>
<editLevel/>
<ynIsRequired/>
</TextBox>
<Memo>
<elementType>Memo</elementType>
<elementName/>
<elementLabel/>
<elementLabelClass/>
<elementClass/>
<elementPosition/>
<elementCols/>
<elementRows/>
<DefaultValue/>
<xslMember/>
<editLevel/>
<ynIsRequired/>
</Memo>
</ElementTemplates>
</cf_xmldatasource>
<!--- Query the datasource using XPath --->
<cf_xmlquery name = "testQuery" datasource = "ds_ElementTemplates">
//ElementTemplates/TextBox
</cf_xmlquery>
<!--- output the Query --->
<cfoutput query = "testQuery">
elementType is #TextBox_elementType#<br />
elementName is #TextBox_elementName#<br />
elementLabel is #TextBox_elementLabel#<br />
</cfoutput>
-----------------+
tom dyson
t: +44 (0)1608 811870
m: +44 (0)7958 752657
http://torchbox.com
> I have a xml file that I need to pull a specific element and it's children.
> I'm passing in the element name upon which I need to filter out it's children.
> I've figured it out using a cfloop to find the element then another cfloop to
> pull its children. Is there an easier way to do this?
>
> Here's xml snipet:
> <?xml version="1.0" encoding="iso-8859-1"?>
> <ElementTemplates>
> <TextBox>
> <elementType>TextBox</elementType>
> <elementName/>
> <elementLabel/>
> <elementLabelClass/>
> <elementClass/>
> <elementPosition/>
> <elementSize/>
> <elementMaxLength/>
> <DefaultValue/>
> <xslMember/>
> <editLevel/>
> <ynIsRequired/>
> </TextBox>
> <Memo>
> <elementType>Memo</elementType>
> <elementName/>
> <elementLabel/>
> <elementLabelClass/>
> <elementClass/>
> <elementPosition/>
> <elementCols/>
> <elementRows/>
> <DefaultValue/>
> <xslMember/>
> <editLevel/>
> <ynIsRequired/>
> </Memo>
> </ElementTemplates>
>
> I' want to pull TextBox element and there children. Here's how I'm doing it
> after I've created an object representing the XML chunk:
>
> <cfloop
> collection="#oElementTemplates.selectNodes("//ElementTemplates/TextBox")#"
> item="oFormElement">
> <cfscript>
> oElementChildNodes = oFormElement.childNodes;
> WriteOutput("oFormElements: " & oFormElement.text & "<br>");
> WriteOutput("oElementChildNodes: " & oElementChildNodes.length & "<br>");
> </cfscript>
>
> <cfloop collection="#oElementChildNodes#" item="oElementNode">
> <cfscript>
> WriteOutput("oElementNode: " & oElementNode.nodeName & "<br>");
> </cfscript>
> </cfloop>
> </cfloop>
>
> Thanks - Tom
-----------------------+
cf-xml mailing list
list: [EMAIL PROTECTED]
admin: [EMAIL PROTECTED]
home: http://torchbox.com/xml