I
Ivan Dwyer
I hope my Subject makes sense
I'm developing a front end form that generates an XML file that is the
nprocessed through a templating system. Unfortunately, the format the
XML needs to be in has proven to be difficult for me to reference with
any perl modules. Here's sample XML.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE record>
<record name="test" type="content">
<item name="Title">
<value>Testing</value>
</item>
<item name="Author">
<value>Ivan</value>
</item>
<item name="Author_Desc">
<value>Stumped</value>
</item>
<item name="List">
<value>
<item name="List_ID">
<value>1</value>
</item>
<item name="List_Title">
<value>List Title 1</value>
</item>
</value>
</item>
<item name="List">
<item name="List_ID">
<value>2</value>
</item>
<item name="List_Title">
<value>List Title 2</value>
</item>
</item>
</record>
Unfortunately, all elements have to be <item name="something">, and
when there are multiple instances of the same type, they have to have
the same name.
I have no problem accessing the individual elements using XML::Simple.
my $s = XML::Simple->new();
my $data = $s->XMLin($file);
print "$data->{item}->{Title}->{value}", etc.
My problem occurs when trying to iterate through the list items. I've
tried a few modules like XML:arser, XML::XPath, and XML::Twig, but I
have yet to find a way to access a value based on one of the list
element attributes. My closest attempt has been with XPath. I'm able
to get the list blocks into nodes, but I get stuck from there.
my $x = XML::XPath->new( filename => $file );
my $nodeset = $x->findnodes( "/record/item[\@name='List']" );
foreach my $node ( $nodeset->get_nodelist )
{
##### Lost in Here ######
# Need List->List_ID->value and List->List_Title->value somehow
}
Would anyone have any advice on a solution with XPath, or any
assistance as to a better module choice? I would greatly appreciate
any help. Thanks,
Ivan Dwyer
I'm developing a front end form that generates an XML file that is the
nprocessed through a templating system. Unfortunately, the format the
XML needs to be in has proven to be difficult for me to reference with
any perl modules. Here's sample XML.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE record>
<record name="test" type="content">
<item name="Title">
<value>Testing</value>
</item>
<item name="Author">
<value>Ivan</value>
</item>
<item name="Author_Desc">
<value>Stumped</value>
</item>
<item name="List">
<value>
<item name="List_ID">
<value>1</value>
</item>
<item name="List_Title">
<value>List Title 1</value>
</item>
</value>
</item>
<item name="List">
<item name="List_ID">
<value>2</value>
</item>
<item name="List_Title">
<value>List Title 2</value>
</item>
</item>
</record>
Unfortunately, all elements have to be <item name="something">, and
when there are multiple instances of the same type, they have to have
the same name.
I have no problem accessing the individual elements using XML::Simple.
my $s = XML::Simple->new();
my $data = $s->XMLin($file);
print "$data->{item}->{Title}->{value}", etc.
My problem occurs when trying to iterate through the list items. I've
tried a few modules like XML:arser, XML::XPath, and XML::Twig, but I
have yet to find a way to access a value based on one of the list
element attributes. My closest attempt has been with XPath. I'm able
to get the list blocks into nodes, but I get stuck from there.
my $x = XML::XPath->new( filename => $file );
my $nodeset = $x->findnodes( "/record/item[\@name='List']" );
foreach my $node ( $nodeset->get_nodelist )
{
##### Lost in Here ######
# Need List->List_ID->value and List->List_Title->value somehow
}
Would anyone have any advice on a solution with XPath, or any
assistance as to a better module choice? I would greatly appreciate
any help. Thanks,
Ivan Dwyer