Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML parser

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Right then I have got an XML file (not WDDX but XML), that i want to read in and then write to a database. I have seen an article on Allaire that says that an XML file needs to be turned into a WDDX format XML file before CFWDDX can read it. Does anyone know of a parser that would read an XML file and output WDDX format. I can't get onto the wddx site as it has been down for the best part of this week to find out for myself. Am I on the right lines here or just way off. I have been able to do this using WDDX to a file and the read that back in again, now trying to do with a pure XML file and having difficulties. any help appreciated!
 
Take a look at these:

CF XML Toolkit by Torchbox
The Torchbox CF XML Toolkit has been launched: this suite of open source custom tags is intended to simplify the task of building XML applications in ColdFusion. It includes reference, examples and Studio extensions.

<cf_SOXML> by SiteObjects
SOXML provides ColdFusion programmers with an easy to use interface for integration of XML with CF. This custom tag is open-source (of course), free, and action based.
- tleish
 
Any luck arperry?

If you understand the difference between a WDDX packet and your own XML format, its obvious why we can't expect Cold Fusion to understand whats contained within your file.

WDDX is accessed with CFWDDX. This tag can output a WDDX packet from a Cold Fusion array or structure, or it can read in a WDDX packet and output an array or structure object. If you can explain whats inside the XML file, and how its data is organized I should be able to tell you how much work is involved to get your XML tags converted into something CFWDDX can understand.
-
In XML the names of the tags used to delimit the data are specific to the standard being used. In WDDX standard, the tag <var></var> surrounds any object or key of an object. Further down the page, in the WDDX packet example the first object we have is an ARRAY called 'lakes'. It has 4 dimensions (or keys). This array has 4 variables now.

lakes[1]
lakes[2]
lakes[3]
lakes[4]

Each of these variables is a structure. They are STRUCTURES of ARRAYS. Structures are objects. Each structure contains keys, which are referenced by text not numbers and are stored in no particular order. Lakes[1] contains 3 keys, as does Lakes[2], Lakes[3], and Lakes[4].

lakes[1]['LAKEID'] = 2
lakes[1]['NAME'] = Whiskey Lake
lakes[1]['FISHLIST'] = Rainbow trout,Northern sucker fish,Halibut

lakes[2]['LAKEID'] = 3
lakes[2]['NAME'] = Lake Mead
lakes[2]['FISHLIST'] = Carp,Albino carp,Dead carp

... etc ...

WDDX packet example:
<var name='LAKES'>
<array length='4'>
<struct>
<var name='LAKEID'><number>2</number></var>
<var name='NAME'><string>Whiskey Lake</string></var>
<var name='FISHLIST'><string>Rainbow trout,Northern sucker fish,Halibut</string></var>
</struct>
<struct>
<var name='LAKEID'><number>3</number></var>
<var name='NAME'><string>Lake Mead</string></var>
<var name='FISHLIST'><string>Carp,Albino carp,Dead carp</string></var>
</struct>
<struct>
<var name='LAKEID'><number>4</number></var>
<var name='NAME'><string>Lake Michigan</string></var>
<var name='FISHLIST'><string>Coke bottle,plastic ring for cans,biological waste</string></var>
</struct>
<struct>
<var name='LAKEID'><number>5</number></var>
<var name='NAME'><string>New Lake</string></var>
<var name='FISHLIST'><string>fishA,fishb,fishc</string></var>
</struct>
</array>
</var>
-

1. CREATE a packet
If you had the following CFSCRIPT:
<CFSCRIPT>
tempStruct = structnew();
tempStruct['COLOR'] = 'Red';
tempStruct['SIZE'] = 'Large';
tempStruct['SEX'] = 'M';

order = structnew();
order = structcopy(tempstruct);

</CFSCRIPT>
You would have a structure object with 3 keys describing one customer's order.

You'd convert it into a WDDX packet, and write the file.
<CFWDDX action=&quot;CFML2WDDX&quot; input=&quot;#order#&quot; output=&quot;content&quot;>

<CFFILE ACTION=&quot;write&quot;
FILE=&quot;temp.txt&quot;
OUTPUT=
'#content#'>

2. READ a packet
If you had the following packet:
<CFSET input =
'
<wddxPacket version='1.0'><header></header>
<data>
<struct>
<var name='COLOR'><string>Red</string></var>
<var name='SIZE'><string>Large</string></var>
<var name='SEX'><string>M</string></var>
</struct>
</data>
</wddxPacket>
'>

<CFWDDX action=&quot;WDDX2CFML&quot; input=&quot;#input#&quot; output=&quot;order&quot;>

<CFOUTPUT>#order.color#,#order.size#,#order.sex#</CFOUTPUT>
Would show: Red,Large,M

hope this makes a distinction easier. lets see your XML file and tags and any description you can provide
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top