//xmlfile = xmlparse(cfhttp.filecontent); //Parses the XML xmlqry = QueryNew("ID, shortName, longName, State, Country"); //Sets a query for output QueryAddRow(xmlqry,xmlsize); for(a=1;a LTE xmlsize;a=a+1) { QuerySetCell(xmlqry,"ID",xmlfile.ResponseGetArea.Areas.area[a].ID.xmlText,a) ; QuerySetCell(xmlqry,"ShortName",xmlfile.ResponseGetAreas.Area.area[a].Shortn ame.xmlText,a); QuerySetCell(xmlqry,"LongName",xmlfile.ResponseGetArea.Areas.area[a].LongNam e.xmlText,a); QuerySetCell(xmlqry,"State",xmlfile.ResponseGetArea.Areas.area[a].State.xmlT ext,a); QuerySetCell(xmlqry,"Country",xmlfile.ResponseGetArea.Areas.area[a].Country. xmlText,a); } SELECT * FROM xmlqry ORDER BY ID DESC ID: #ID#, state: #state#, country: #country#
 
here's the xml file: - 0 - - 20 FL - Jacksonville Golf Florida - Jacksonville Golf FL US - 45 FL - Orlando Golf Florida - Orlando Golf FL US - [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Eymard [ip] => webmaster@aklan [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> 0 20 FL - Jacksonville Golf Florida - Jacksonville Golf FL US 45 FL - Orlando Golf Florida - Orlando Golf FL US data = XmlParse(someXml); area = XMLSearch(someXml, "/ResponseGetArea/Areas/Area"); ID: #area[x].ID.xmlText#
ShortName: #area[x].ShortName.xmlText#
LongName: #area[x].LongName.xmlText#
State: #area[x].State.xmlText#
Country: #area[x].COuntry.xmlText#
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => cf_menace [ip] => amoreno@factors [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Parsing XML in mx7 - Coldfusion - Advanced Techniques

Parsing XML in mx7 - Coldfusion - Advanced Techniques

Hi, Can someone help me p the following XML? I'm new to XML and I tried different examples but I can't output it properly. Thank you. <cfset xmlfile = xmlp(cfhttp.filecontent)> <!--- //Ps the XML ---> <cfset xmlsize = arraylen(xmlfile.ResponseGetArea.xmlchildren)> <!--- <cfdump var="#xmlfile#"><cfabort> ---> <cfif xmlsize NEQ 0> <cfscript> //xmlfile = xmlp(cfhttp.filecontent); //Ps the XML xmlqry = QueryNew("ID, shortName, longName, State, Country"); //Sets a query for output QueryAddRow(xmlqry,xmlsize); for(a=1;a LTE xmlsize;a=a+1) { QuerySetCell(xmlqry,"ID",xmlfile.ResponseGetArea.A reas.area[a].ID.xmlText,a) ; QuerySetCell(xmlqry,"ShortName",xmlfile.ResponseGe tAreas.Area.area[a].Shortn ame.xmlText,a); QuerySetCell(xmlqry,"LongName",xmlfile.ResponseGet Area.Areas.area[a].LongNam e.xmlText,a); QuerySetCell(xmlqry,"State",xmlfile.ResponseGetAre a.Areas.area[a].State.xmlT ext,a); QuerySetCell(xmlqry,"Country",xmlfile.ResponseGetA rea.Areas.area[a].Country. xmlText,a); } </cfscript> <cfquery name="getAreaList" dbtype="query"> SELECT * FROM xmlqry ORDER BY ID DESC </cfquery> ...

  1. #1

    Default Parsing XML in mx7

    Hi,

    Can someone help me p the following XML? I'm new to XML and I tried
    different examples but I can't output it properly.

    Thank you.


    <cfset xmlfile = xmlp(cfhttp.filecontent)> <!--- //Ps the XML --->
    <cfset xmlsize = arraylen(xmlfile.ResponseGetArea.xmlchildren)>

    <!--- <cfdump var="#xmlfile#"><cfabort> --->
    <cfif xmlsize NEQ 0>

    <cfscript>
    //xmlfile = xmlp(cfhttp.filecontent); //Ps the XML
    xmlqry = QueryNew("ID, shortName, longName, State, Country"); //Sets a
    query for output

    QueryAddRow(xmlqry,xmlsize);

    for(a=1;a LTE xmlsize;a=a+1) {

    QuerySetCell(xmlqry,"ID",xmlfile.ResponseGetArea.A reas.area[a].ID.xmlText,a)
    ;

    QuerySetCell(xmlqry,"ShortName",xmlfile.ResponseGe tAreas.Area.area[a].Shortn
    ame.xmlText,a);

    QuerySetCell(xmlqry,"LongName",xmlfile.ResponseGet Area.Areas.area[a].LongNam
    e.xmlText,a);

    QuerySetCell(xmlqry,"State",xmlfile.ResponseGetAre a.Areas.area[a].State.xmlT
    ext,a);

    QuerySetCell(xmlqry,"Country",xmlfile.ResponseGetA rea.Areas.area[a].Country.
    xmlText,a);
    }
    </cfscript>

    <cfquery name="getAreaList" dbtype="query">
    SELECT *
    FROM xmlqry
    ORDER BY ID DESC
    </cfquery>

    <cfoutput query="getAreaList">
    ID: #ID#, state: #state#, country: #country#<br>
    </cfoutput>
    <cfelse>
    &nbsp;
    </cfif>

    here's the xml file:

    <?xml version="1.0" encoding="utf-8" ?>
    - <ResponseGetArea xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://onlinereservationsystems.com/api/">
    <ErrorCode>0</ErrorCode>
    - <Areas>
    - <Area>
    <ID>20</ID>
    <ShortName>FL - Jacksonville Golf</ShortName>
    <LongName>Florida - Jacksonville Golf</LongName>
    <State>FL</State>
    <Country>US</Country>
    </Area>
    - <Area>
    <ID>45</ID>
    <ShortName>FL - Orlando Golf</ShortName>
    <LongName>Florida - Orlando Golf</LongName>
    <State>FL</State>
    <Country>US</Country>
    </Area>
    - <Area>
    </Areas>
    </ResponseGetArea>

    Eymard Guest

  2. #2

    Default Re: Parsing XML in mx7

    For some reason, the XML won't p with all the attributes in the root node.
    I've tested this code and it works.



    <cfxml variable="someXml">
    <!--- <ResponseGetArea xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://onlinereservationsystems.com/api/"> --->
    <ResponseGetArea>
    <ErrorCode>0</ErrorCode>
    <Areas>
    <Area>
    <ID>20</ID>
    <ShortName>FL - Jacksonville Golf</ShortName>
    <LongName>Florida - Jacksonville Golf</LongName>
    <State>FL</State>
    <Country>US</Country>
    </Area>
    <Area>
    <ID>45</ID>
    <ShortName>FL - Orlando Golf</ShortName>
    <LongName>Florida - Orlando Golf</LongName>
    <State>FL</State>
    <Country>US</Country>
    </Area>
    </Areas>
    </ResponseGetArea>
    </cfxml>

    <cfscript>
    data = XmlP(someXml);

    area = XMLSearch(someXml, "/ResponseGetArea/Areas/Area");
    </cfscript>

    <cfoutput>
    <cfloop index="x" from="1" to="#ArrayLen(area)#">
    ID: #area[x].ID.xmlText#<br />
    ShortName: #area[x].ShortName.xmlText#<br />
    LongName: #area[x].LongName.xmlText#<br />
    State: #area[x].State.xmlText#<br />
    Country: #area[x].COuntry.xmlText#
    <hr />
    </cfloop>
    </cfoutput>

    cf_menace Guest

  3. #3

    Default Re: Parsing XML in mx7

    hi,

    Thanks. I was able to do it this way also:

    <cfset xmlsize = arraylen(xmlfile.ResponseGetArea.Areas.Area.xmlchi ldren)>

    <cfif xmlsize NEQ 0>

    <cfscript>
    //xmlfile = xmlp(cfhttp.filecontent); //Ps the XML
    xmlqry = QueryNew("ID, shortName, longName, State, Country"); //Sets a
    query for output

    QueryAddRow(xmlqry,xmlsize);

    for(a=1;a LTE xmlsize;a=a+1) {

    QuerySetCell(xmlqry,"ID",xmlfile.ResponseGetArea.A reas.Area[a].ID.xmlText,a)
    ;

    QuerySetCell(xmlqry,"ShortName",xmlfile.ResponseGe tArea.Areas.area[a].Shortn
    ame.xmlText,a);

    QuerySetCell(xmlqry,"LongName",xmlfile.ResponseGet Area.Areas.area[a].LongNam
    e.xmlText,a);

    QuerySetCell(xmlqry,"State",xmlfile.ResponseGetAre a.Areas.Area[a].State.xmlT
    ext,a);

    QuerySetCell(xmlqry,"Country",xmlfile.ResponseGetA rea.Areas.Area[a].Country.
    xmlText,a);
    }
    </cfscript>

    Eymard Guest

Similar Threads

  1. Parsing U3D
    By Kenney_Wong@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 2
    Last Post: February 25th, 03:18 PM
  2. XML Parsing
    By Doug La Farge in forum PHP Programming
    Replies: 13
    Last Post: July 12th, 06:03 PM
  3. Parsing URL
    By Mercedissa1@netscape.net in forum PERL Beginners
    Replies: 2
    Last Post: September 9th, 08:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •