Best CF XML practices

Is what I am doing considered okay

Page 1 of 1

0 Replies - 1250 Views - Last Post: 28 July 2009 - 11:35 AM Rate Topic: -----

#1 xheartonfire43x   User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Best CF XML practices

Posted 28 July 2009 - 11:35 AM

I am trying to create a small application for one of my client's websites that when a user submits a contact form the data is uploaded to their CRM system via an email. So the XML is put into the body of the email. I just want to make sure that the way I am creating my XML is an okay way to do it or if there is a much simpler way.

		<cfscript>
			//Run SQL
			getContact = getContact(
				contactID = ARGUMENTS.contactID,
				contactTable = ARGUMENTS.contacttable
			);
			//Contact will always be needed
			contact = contact(
				getContact = getContact,
				contactTable = contactTable
			);
			
			//Begin writing XML
			contactXML = '<customer>' & chr(13);
			contactXML = contactXML & '<contact primarycontact="1">' & chr(13);
			contactXML = contactXML & '<name part="full" type="individual">' & contact.name & '</name>' & chr(13);
			contactXML = contactXML & '<email>' & contact.email & '</email>' & chr(13);
			for(phone = 1; phone <= arrayLen(contact.phone); phone = phone++){
				contactXML = contactXML & '<phone type="' & contact.phone[phone][1] & '" time="' & contact.phone[phone][3] & '" preferredcontact="' & contact.phone[phone][4] & '">' & contact.phone[phone][2] & '</phone>' & chr(13);
			}
			for(address = 1; address <= arrayLen(contact.address); address = address++){
				contactXML = contactXML & '<address type="' & contact.address[address][1] & '">' & chr(13);
				contactXML = contactXML & '<street>' & contact.address[address][2] & '</street>' & chr(13);
				contactXML = contactXML & '<apartment>' & contact.address[address][3] & '</apartment>' & chr(13);
				contactXML = contactXML & '<city>' & contact.address[address][4] & '</city>' & chr(13);
				contactXML = contactXML & '<regioncode>' & contact.address[address][5] & '</regioncode>' & chr(13);
				contactXML = contactXML & '<postalcode>' & contact.address[address][6] & '</postalcode>' & chr(13);
				contactXML = contactXML & '<country>' & contact.address[address][7] & '</country>' & chr(13);
			}
			contactXML = contactXML & '</contact>' & chr(13);
			contactXML = contactXML & '</customer>' & chr(13);
		</cfscript>



The struct is built by a CFC Method that runs a query and then builds it on that.

I really need to dust off my ColdFusion books and read up on the XML stuff.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1