Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Working with XML

LEGEND ,
Jun 27, 2011 Jun 27, 2011

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,

^_^

392
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 27, 2011 Jun 27, 2011
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

Translate
LEGEND ,
Jun 27, 2011 Jun 27, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2011 Jun 27, 2011

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,

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2011 Jun 27, 2011
LATEST
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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources