1 Reply Latest reply on Aug 4, 2009 9:05 PM by richardELeach

    parsing a XML file using bracket notation

    richardELeach Level 1

      Hi Gang-


      I have been given the task to parse a .xml file.


      The xml file contains element names that contain hyphens, so I've read that bracket notation is the only way to go. According to Ben Forta I have built the following code, but because of what I believe to be a simple syntax issue that I simply cannot put my finger on I can not get it to work:


      1. <cffile action="read" file="/Applications/Coldfusion8/wwwroot/config/ModelGlue.xml" variable="xmldoc">

      2. <cfset mydoc=XmlParse(xmldoc)>

      3. <cfset newLen=#arraylen(mydoc.modelglue.xmlchildren[2].xmlChildren)#>

      4. <cfoutput>

      5.     <cfloop from="1" to="#newLen#" index="i">

      6.         xmlObject["mydoc"]["modelglue"]["event-handlers"]["event-handler"][i].xmlAttributes["name "]<br>
      7.     </cfloop>
      8. </cfoutput>


      When I run the code line 6 literally appears on screen the proper amount of times, according to the "to" value in my loop.


      I tried putting pound signs around line 6 but it returns an error saying that "... xmlObject is undefined..."


      Because of the hyphens it seems that I'm forced to use the bracket notation (I'm OK with that) but does anyone know how to render line 6 to obtain the value?


      Thanks in advance,


        • 1. Re: parsing a XML file using bracket notation
          richardELeach Level 1


          This is what you get for working 12 hours straight....


          I changed:

          xmlObject["mydoc"]["modelglue"]["event-handlers"]["event-handler"][i].xmlAttrib utes["name"]<br>



          #mydoc["modelglue"]["event-handlers"]["event-handler"][i].xmlAttrib utes["name"]#<br>


          xmlObject is the name of my xml object in memory, and then you reference from the root of the xml doc down the chain.


          Sorry for the inconvenience,