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

XML::Simple help - not parsing entire file?

Status
Not open for further replies.

rkmase

IS-IT--Management
Apr 18, 2007
3
US
I'm trying to parse the following XML (see bottom of post) with XML::Simple, yet it will only parse certain parts. I've attempted all sorts of combinations of KeyAttr, but I'm beginning to think thats not the problem. You can see below that most of the values are <datafield> with a "tag" attribute. The XML::Simple parser will only output the ones with tag="022" and "245". I fail to see why it would output those but none of the others OR the <controlfield> tags.

Any help would be great - stumped!


------------------------
Code:
<?xml version = "1.0" encoding = "UTF-8"?>
<x_server_response version="4.07 (233)">
	<present_response>
		<record xmlns="[URL unfurl="true"]http://www.loc.gov/MARC21/slim"[/URL]
		xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
		xsi:schemaLocation="[URL unfurl="true"]http://www.loc.gov/MARC21/slim[/URL]
		[URL unfurl="true"]http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">[/URL]
		<leader>^^^^^naa^^2200313^^^4500</leader>
		<controlfield tag="001">2009600369</controlfield>
		<datafield tag="035" ind1=" " ind2=" ">
			<subfield code="b">0015376</subfield>
		</datafield>
		<datafield tag="245" ind1="1" ind2="0">
			<subfield code="a">WorkChoices is unfair, says Howard: John Howard has finally conceded that WorkChoices laws are unfair and has dished out a 'safety net' with more holes than Swiss cheese.</subfield>
		</datafield>
		<datafield tag="210" ind1=" " ind2=" ">
			<subfield code="a">LAMP</subfield>
		</datafield>
		<datafield tag="514" ind1=" " ind2=" ">
			<subfield code="a">20070706</subfield>
		</datafield>
		<datafield tag="546" ind1=" " ind2=" ">
			<subfield code="a">English</subfield>
		</datafield>
		<datafield tag="902" ind1=" " ind2=" ">
			<subfield code="a">This publication is protected by US and international copyright laws and its content may not be copied without the copyright holder's express written permission except for the print or download  capabilities of the retrieval software used for access. This content is intended solely for the use of the individual user.</subfield>
		</datafield>
		<controlfield tag="LDR">^^^^^naa^^2200313^^^4500</controlfield>
		<controlfield tag="005">20070706</controlfield>
		<controlfield tag="008">^^^^^^^2007^^^^^^^^^^^^^^^^^^^^^^^^eng^^^</controlfield>
		<datafield tag="016" ind1=" " ind2=" ">
			<subfield code="a">2009600369</subfield>
		</datafield>
		<datafield tag="022" ind1=" " ind2=" ">
			<subfield code="a">0047-3936</subfield>
		</datafield>
		<datafield tag="072" ind1=" " ind2=" ">
			<subfield code="a">journal article</subfield>
		</datafield>
		<datafield tag="072" ind1=" " ind2=" ">
			<subfield code="a">pictorial</subfield>
		</datafield>
		<datafield tag="362" ind1=" " ind2=" ">
			<subfield code="a">2007 Jun, 64 (5)</subfield>
			<subfield code="b">2007</subfield>
		</datafield>
		<datafield tag="650" ind1=" " ind2="4">
			<subfield code="a">Employer-Employee Relations--Australia</subfield>
		</datafield>
		<datafield tag="650" ind1=" " ind2=" ">
			<subfield code="a">Australia</subfield>
		</datafield>
		<datafield tag="650" ind1=" " ind2=" ">
			<subfield code="a">Government</subfield>
		</datafield>
		<datafield tag="650" ind1=" " ind2=" ">
			<subfield code="a">Labor Unions</subfield>
		</datafield>
		<datafield tag="650" ind1=" " ind2=" ">
			<subfield code="a">Public Figures</subfield>
		</datafield>
		<datafield tag="773" ind1=" " ind2=" ">
			<subfield code="t">Lamp</subfield>
			<subfield code="g">2007 Jun 64 (5): 19</subfield>
			<subfield code="m">64 (5)</subfield>
			<subfield code="p">19</subfield>
			<subfield code="x">0047-3936</subfield>
		</datafield>
		<datafield tag="945" ind1=" " ind2=" ">
			<subfield code="d">2007 Jun</subfield>
			<subfield code="m">64</subfield>
			<subfield code="n">5</subfield>
			<subfield code="t">Lamp</subfield>
			<subfield code="p">19</subfield>
		</datafield>
		<datafield tag="SID" ind1=" " ind2=" ">
			<subfield code="a">Z39</subfield>
			<subfield code="b">EBSCO_CIN</subfield>
			<subfield code="d">FCL03400</subfield>
			<subfield code="i">002706</subfield>
			<subfield code="j">000001</subfield>
			<subfield code="s">000180</subfield>
			<subfield code="t">CINAHL (EBSCO)</subfield>
		</datafield>
		<controlfield tag="RAN">026</controlfield>
		<datafield tag="YR " ind1=" " ind2=" ">
			<subfield code="a">2007</subfield>
		</datafield>
		<controlfield tag="SET">000180</controlfield>
		</record>
	<session_id new_session="N">xxxxxxxxxxxxxx</session_id>
	</present_response>
</x_server_response>
 
I don't observe any such problem. Put your XML in the DATA block of the below script, and examine the output. If you can name a single specific piece of data that is missing, we might be able to help. But all things appear to be in working order.

Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]XML::Simple[/green] [red]qw([/red][purple]XMLin[/purple][red])[/red][red];[/red]
[black][b]use[/b][/black] [green]Data::Dumper[/green][red];[/red]

[black][b]use[/b][/black] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$data[/blue] = [url=http://perldoc.perl.org/functions/do.html][black][b]do[/b][/black][/url] [red]{[/red][url=http://perldoc.perl.org/functions/local.html][black][b]local[/b][/black][/url] [blue]$/[/blue][red];[/red] <DATA>[red]}[/red][red];[/red]
[black][b]my[/b][/black] [blue]$ref[/blue] = [maroon]XMLin[/maroon][red]([/red][blue]$data[/blue][red])[/red][red];[/red]

[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [maroon]Dumper[/maroon][red]([/red][blue]$ref[/blue][red])[/red][red];[/red]

[gray][i]# Put your XML file below __DATA__[/i][/gray]

[teal]__DATA__[/teal]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
Core (perl 5.8.8) Modules used :
[ul]
[li]Data::Dumper - stringified perl data structures, suitable for both printing and eval[/li]
[/ul]
Other Modules used :
[ul]
[li]XML::Simple[/li]
[/ul]
[/tt]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top