Copy link to clipboard
Copied
Hello, everyone.
I'm trying to build a module that will take XML that is inserted into a variable with XMLparse() from an uploaded .xml document, and go through ALL child nodes. Each node needs to be checked to see if a particular parameter is contained within (ID, or Name, or Size, etc.) Any node that contains one of the sought-after parameters, I need to get the value of that parameter (integer) and add it mathematically to an initialized variable that starts at 0.
Is there a built-in CF function (or a UDF) that will do this? Or will I have to build a multiple-nested loop to check for this?
Thanks,
^_^
Since I will not know in advance which nodes will or will not have Children, nor whether or not any of the Children will have the name or id parameter, how do I determine if a node has an array OR a parameter?
Read up on xpath first. Then ask questions like this after that.
--
Adam
Copy link to clipboard
Copied
No. There will be no special built-in CF function to automatically fulfil you're specific XML schema and requirements. CF is good but it ain't that good.
However one can use xmlSearch() to do an xpath search to extract subsets of nodes / attributes as an array, which one can then loop over fairly easily to tally up whatever it is you need to do.
--
Adam
Copy link to clipboard
Copied
Thanks, Adam. I'll look into xmlSearch().
Meanwhile, let me post some example XML data.
<rootElement>
<DataA>
<ChildA>
<Child1 name="this" id="1"/>
</ChildA>
<ChildB>
<Child1>
<Grandchild1 name="that" id="2"/>
</Child1>
</ChildB>
<ChildC>
<Child1>
<Grandchild1>
<AnotherGrandchild name="where" id="9"/>
<AnotherGrandchild1 name="when" id="12"/>
</Grandchild1>
<Grandchild2>
<AnotherGrandchild1>
<KeepGoing>
<Anymore name="whendoesitend" id="3"/>
</KeepGoing>
</AnotherGrandchild1>
</Grandchild2>
</Child1>
<Child2/>
</ChildC>
</DataA>
Since I will not know in advance which nodes will or will not have Children, nor whether or not any of the Children will have the name or id parameter, how do I determine if a node has an array OR a parameter? I assume ArrayLen for the array (0 = no children?) What about the parameters? Check for isDefined?
Thanks,
^_^
Copy link to clipboard
Copied
Since I will not know in advance which nodes will or will not have Children, nor whether or not any of the Children will have the name or id parameter, how do I determine if a node has an array OR a parameter?
Read up on xpath first. Then ask questions like this after that.
--
Adam