midasxl's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Active Members
Active Posts:
191 (0.09 per day)
Joined:
03-December 08
Profile Views:
7,247
Last Active:
User is offline Apr 25 2014 06:32 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0

Latest Visitors

Icon   midasxl has not set their status

Posts I've Made

  1. In Topic: XmlSearch for node with specific attribute value; add child element

    Posted 24 Apr 2014

    I am certainly trying everything. So far dead ends at each attempt. It's probably simple, I just need to wrap my head around it. So let's recap. Here is a sample of the xml I am dealing with:

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="blog.xsl"?>
    <demoChanges>
    	<entry ID="212332">
    		<heading>Test</heading>
    		<descr>&lt;p&gt;Test&lt;/p&gt;</descr>
    		<author>Mark</author>
    		<date>April 24, 2014</date>
    		<cert>Mark</cert>
    		<draft>no</draft>
    		<id>212332</id>
    		<comments/>
    	</entry>
    	<entry ID="43235">
    		<heading>Test</heading>
    		<descr>&lt;p&gt;&lt;br /&gt;Test&lt;/p&gt;</descr>
    		<author>Mark</author>
    		<date>April 24, 2014</date>
    		<cert>Mark</cert>
    		<draft>no</draft>
    		<id>43235</id>
    		<comments/>
    	</entry>
    	<entry ID="740515">
    		<heading>New</heading>
    		<descr>&lt;p&gt;New&lt;/p&gt;</descr>
    		<author>Mark</author>
    		<date>April 24, 2014</date>
    		<cert>Mark</cert>
    		<draft>no</draft>
    		<id>740515</id>
    		<comments/>
    	</entry>
    </demoChanges>
    
    


    Using ColdFusion I read the file in, parse it, and then locate the exact entry node that has the id attribute that matches the number passed in from the form scope.

    <cffile action="read" file="/path/to/the/blog.xml" variable="xmlFile">
    
    <cfset myXml = XmlParse(xmlFile)>
    
    <cfset myNode = XmlSearch(myXml, "demoChanges/entry[@ID=#threadid#]") />
    
    


    Dumping #myNode# to the page shows me the correct xml node that I am looking for (see array.jpg).

    There is a child element within this entry node called "comments". (see array2.jpg). Now that I have identified the correct entry node, I want to now use that and target the "comments" child element and add an element called "comment"

    The end result would look something like this (see the entry node with id="740515"):

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="blog.xsl"?>
    <demoChanges>
    	<entry ID="212332">
    		<heading>Test</heading>
    		<descr>&lt;p&gt;Test&lt;/p&gt;</descr>
    		<author>Mark</author>
    		<date>April 24, 2014</date>
    		<cert>Mark</cert>
    		<draft>no</draft>
    		<id>212332</id>
    		<comments/>
    	</entry>
    	<entry ID="43235">
    		<heading>Test</heading>
    		<descr>&lt;p&gt;&lt;br /&gt;Test&lt;/p&gt;</descr>
    		<author>Mark</author>
    		<date>April 24, 2014</date>
    		<cert>Mark</cert>
    		<draft>no</draft>
    		<id>43235</id>
    		<comments/>
    	</entry>
    	<entry ID="740515">
    		<heading>New</heading>
    		<descr>&lt;p&gt;New&lt;/p&gt;</descr>
    		<author>Mark</author>
    		<date>April 24, 2014</date>
    		<cert>Mark</cert>
    		<draft>no</draft>
    		<id>740515</id>
    		<comments>
                        <comment>Comment Text information goes here.</comment>
                    </comments>
            </entry>
    </demoChanges>
    
    


    I'm trying something like this:

    <cfset myXml.demoChanges.entry[which one?].comments.XmlChildren = XmlElemNew(myXml,"comment")>
    <cfset myXml.demoChanges.entry[which one?].comments.comment.xmltext = #formThreadDescr#>
    
    


    As you can see my problem ( I think ) is that I do not know how to target the entry that has the attribute id value I'm looking for. Now, I know I have identified that node using XmlSearch, but the result is an array, so I cannot use that in the <cfset>. For example, this does not work:

    <cfset myXml.myNode.comments.XmlChildren = XmlElemNew(myXml,"comment")>
    
    


    It errors out on the 'myNode' part saying you cannot use an array in the dot notation.

    I will continue to research, but if anyone reads this and has any ideas, I will be very grateful for your time and assistance.

    Thanks!
  2. In Topic: XmlSearch for node with specific attribute value; add child element

    Posted 23 Apr 2014

    Craig328,
    Thanks for your response!

    This line:

    <cfset myNode.comment = XmlElemNew(myXml, "comment")>
    


    Throws this error:

    You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.

    XmlSearch returns an array, so perhaps I need to use array functions to add elements?
  3. In Topic: Character used as javascript separator. What is it?

    Posted 9 Oct 2013

    View PostCraig328, on 09 October 2013 - 09:23 AM, said:

    Hm. If it evaluated to a comma then you'd think you should be seeing ",light,".


    I do get ",light," when I alert the resultsArr. Then after the pop I alert again and get ",light". Then the code proceeds to trim the first character (the remaining comma).

    $.trim(resultsArr[0])
    
    


    Why all the trouble? Why not just return "light" in the first place??? This is legacy code by the way.

    Thanks!
  4. In Topic: Character used as javascript separator. What is it?

    Posted 9 Oct 2013

    Hello and thanks for youre time. I have a quick question regarding a strange character used as a separator in javascript.

    Coldfusion returned to an ajax block:
    <cfoutput>:-:</cfoutput>
    <cfoutput>#session.themeColor#</cfoutput>
    <cfoutput>:-:</cfoutput>
    
    


    Javascript which consumes the callback (partial):
    success: function(results){
    var resultsArr = results.split(":-:");
    resultsArr.pop();
    }
    
    


    Let's say the #session.themeColor# holds the value of "light".

    I dumped resultsArr and got ",light,"

    After the pop(), the last item in the array was removed and I got ",light"

    So the ":-:" resolves to a comma??? I've never seen this before, so I'm just looking to learn about this one.

    Any guidance will be greatly appreciated as always!

    Thanks!
  5. In Topic: Build Array using CFLOOP with Form Values

    Posted 14 Aug 2013

    This is a fantastic solution and description; thank you very much! It works great. I delve into ColdFusion markup on occasion due to some legacy apps. Now that I have a complete working solution (of this small portion of the overall form), here is this section of the form to possibly benefit others who may view this. Thanks!

    The HTML begins with a div holding a pair of radio buttons. The user has the option of adding additional radio buttons via a jquery clone method. The div around the radio buttons is the tag that is cloned (including its contents). Upon being cloned the names of the radio buttons are changed to differentiate them from the first cloned pair.

    HTML (before clone):
    
    <div>
    <input type="radio" name="DHCP0" value="yes" />  
    <input type="radio" name="DHCP0" value="no" />  
    <input type="hidden" name="dhcpCounter" value="dhcpCounter" />
    </div>
    
    
    


    HTML (after 1 clone):
    
    <div>
    <input type="radio" name="DHCP0" value="yes" />  
    <input type="radio" name="DHCP0" value="no" />  
    <input type="hidden" name="dhcpCounter" value="dhcpCounter" />
    </div>
    
    <div><!-- I am a clone of the above div, appended here -->
    <input type="radio" name="DHCP1" value="yes" />  
    <input type="radio" name="DHCP1" value="no" />  
    <input type="hidden" name="dhcpCounter" value="dhcpCounter" />
    </div>
    
    
    


    I keep track of how many radio pairs using the hidden field "dhcpCounter"

    CFML:
    <cfset dhcpCount = listLen("#FORM.dhcpCounter#", ",")>
    
    


    Then I build an array of the user selections from each radio pair. The form is validated on the front end which requires the user to make a selection; no empty values come across.

    CMFL (cont'd):
    <cfset dhcpCount = listLen("#FORM.dhcpCounter#", ",")>
    <cfset dhcpArray = ArrayNew(1)>
    <cfloop index="i" from="0" to=#dhcpCount#>
       <cfset variables.newArrayVal = "">
       <cfif isDefined("FORM.DHCP#i#")>
          <cfset variables.newArrayVal = FORM["DHCP#i#"]>
          <cfset ArrayAppend(dhcpArray, variables.newArrayVal)>
       </cfif>
    </cfloop>
    
    


    Once the array is built (and this could be up to 9 groups of radio buttons), I process the array into an html email:

    CFML (cont'd):
    <cfloop index="i" from="1" to="#dhcpCount#">
       <cfparam name="dhcpArray[i]" default="na"><!---if not already defined, define it here with the default value--->
       <cfif dhcpArray[i] is not "na">
          <p>Does host obtain IP through DHCP? #dhcpArray[i]#</p>
       </cfif>
    </cfloop>
    
    


    That's the bulk of it at this point. There's a whole lot more going on around this small portion of the form, but this tackles the issue I was having. Hope this helps others, and a BIG thanks to Craig328 for helping me!

    Cheers!

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

midasxl hasn't added any friends yet.

Comments

midasxl has no profile comments yet. Why not say hello?