[thelist] xml and classic asp
der wert
derwert at hotmail.com
Mon Jul 31 18:12:39 CDT 2006
just for completeness, for future ref. if anyone asks the same question but
for php instead of asp, you can refer the individual to this message
note: the $data variable can easily be replace with a post object as was
from the orig. query
it would be done like so $data=$_POST['name_of_xml_data_variable'];
this code parses the data and creates an array with the data in it which can
easily be accesssed
--------------------------------------------start--------------------------------------------
<pre><?php
$data= "
<AddressKeyFormat>
<ConsigneeName>data1a</ConsigneeName>
<AddressLine>data2a</AddressLine>
<PoliticalDivision2>data3a</PoliticalDivision2>
<PoliticalDivision1>data4a</PoliticalDivision1>
<PostcodePrimaryLow>data5a</PostcodePrimaryLow>
<PostcodeExtendedLow>data6a</PostcodeExtendedLow>
<CountryCode>data7a</CountryCode>
</AddressKeyFormat>
<AddressKeyFormat>
<ConsigneeName>data1b</ConsigneeName>
<AddressLine>data2b</AddressLine>
<PoliticalDivision2>data3b</PoliticalDivision2>
<PoliticalDivision1>data4b</PoliticalDivision1>
<PostcodePrimaryLow>data5b</PostcodePrimaryLow>
<PostcodeExtendedLow>data6b</PostcodeExtendedLow>
<CountryCode>data7b</CountryCode>
</AddressKeyFormat>";
preg_match_all("|<([^>]+)>(.*)</[^>]+>|U", $data, $out, PREG_SET_ORDER);
$c =0; $number_of_entries = (count($out)/7);
for ($a = 1; $a <= $number_of_entries; $a++){
for ($b = 0; $b <= 6; $b++){
$ndata[$a][$out[($c)][1]]=$out[($c)][2];
$c++;
}
}
//display array struct and data, for example purposes
print_r ($ndata);
//example of accessing data(accesses the first record of ConsigneeName)
echo $ndata[1]['ConsigneeName']."\n";
//accesses the second record of AddressLine
echo $ndata[2]['AddressLine']."\n";
?></pre>
--------------------------------------------end--------------------------------------------
the end result would be an array that looks like this:
Array
(
[1] => Array
(
[ConsigneeName] => data1a
[AddressLine] => data2a
[PoliticalDivision2] => data3a
[PoliticalDivision1] => data4a
[PostcodePrimaryLow] => data5a
[PostcodeExtendedLow] => data6a
[CountryCode] => data7a
)
[2] => Array
(
[ConsigneeName] => data1b
[AddressLine] => data2b
[PoliticalDivision2] => data3b
[PoliticalDivision1] => data4b
[PostcodePrimaryLow] => data5b
[PostcodeExtendedLow] => data6b
[CountryCode] => data7b
)
)
_________________________________________________________________
Dont just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
More information about the thelist
mailing list