How to Get a Specific Value From XML ColdFusion

Adobe ColdFusion is a rapid application development application typically used for creating Web-based dynamic applications; ColdFusion Markup Language (CFML) is the server-side scripting language used to create these applications. Extensible Markup Language (XML) is a metalanguage designed to aid with the transportation and storage of data. You can use the "XmlSearch" function to search for a specific value or document object. To implement the source code, you can use Microsoft Windows Notepad.

Instructions

    • 1

      Click on the Windows "Start" button, click on "All Programs," click on "Accessories," then click on "Notepad." This will open Windows Notepad.

    • 2

      Copy and paste the following example code into Notepad:

      <?xml version="1.0" encoding="UTF-8"?>

      <employee>

      <name EmpType="Regular">

      <first>John</first>

      <last>Smith</last>

      </name>

      <name EmpType="Contract">

      <first>Sue</first>

      <last>Taylor</last>

      </name>

      </employee>

      Modify the names of the XML elements according to your needs.

    • 3

      Press "Ctrl" and "S" on your keyboard, after which a dialog box will appear. Change the file type to "All Files," change the save folder to "Windows Desktop," type the file name "example.xml," then click on the "Save" button. This will save the file to the Windows Desktop.

    • 4

      Right-click on the Adobe ColdFusion document, click on "Open With," then click on "Notepad." This will open your CFM/CFML file in Windows Notepad.

    • 5

      Copy and paste the following ColdFusion code into the file:

      <cfscript>

      myxmldoc = XmlParse("c:\users\USER_NAME\desktop\example.xml");

      selectedElements = XmlSearch(myxmldoc, "/employee/name/last");

      for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1)

      writeoutput(selectedElements[i].XmlText & "");

      </cfscript>

      Replace "USER_NAME" with the actual name of your user folder in Microsoft Windows. Replace "/employee/name/last" according to the elements that you specify in the XML file.

    • 6

      Press "Ctrl" and "S" on your keyboard to save the file. Exit Notepad.

Related Searches:

References

Comments

Related Ads

Featured