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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing XML

Status
Not open for further replies.

tempname

Programmer
Joined
May 15, 2008
Messages
6
Location
US
With my webservice, as I said it a previous post I get some really funky xml. After testing a bit, I have found a few issues that I am uncertain of.

With in the xml result that I receive, I get back xml like such.

<COLUMNS>
[Tab delimited column data]
</COLUMNS>
<DATA>
[Tab delimited data] (this is the data that I am looking for)
</DATA>
<DATA>
[Tab delimited data] (this is the data that I am looking for)
</DATA>

Now the issue that I am having is after parsing the xml, I am left with something like this and I am not quite sure how to parse the DATA portion of the resulting associative array. Any help with this would be greatly appreciated.

$VAR1 = {
'COLUMNS' => '[Some tab delimited column data here]',
'DATA' => ['Some tab delimited data here','Some tab delimited data here']}.


 
I got it figured out. Here is how I did it.

#parse result xml
my $data = $xml->XMLin($result);

#test print parsed xml
#print Dumper($data);

#create eou variable that holds the parsed xml column names
my $columns = $data->{COLUMNS};
my $counter = 0;
foreach $rData (@{$data->{DATA}}){
@dataList = split("\t", $rData);
@columnList = split("\t", $columns);


for($i=1; $i< @dataList; $i++){
print "Column: ", @columnList[$i], ": ", @dataList[$i] , "\n";

}
$counter = $counter + 1;
print "----------------------------------------------------------------------------------------------------", "\n";
}

print $counter;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top