Trouble Parsing XML File Using Perl

akziag69

New Member
I'm trying to parse an XML manifest file for an Articulate eLearning course (imsmanifest.xml).An excerpt of the XML structure is provided below (I'm trying to drill down to adlcp:masteryscore):\[code\]<?xml version="1.0" encoding="UTF-8"?><manifest xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" version="1.0" identifier="Electrical_Design_Part_3"> <metadata/> <organizations default="Electrical_Design_Part_3_ORG"> <organization identifier="Electrical_Design_Part_3_ORG"> <title>Electrical Design - Part 3</title> <item identifier="Electrical_Design_Part_3_SCO" identifierref="Articulate_Presenter_RES" isvisible="true"> <title>Electrical Design - Part 3</title> <adlcp:masteryscore>65</adlcp:masteryscore> </item> </organization> </organizations> <resources/></manifest>\[/code\]I've tried using XML::Simple and XML::LibXML. I can get these modules to work fine with simpler XML files, but not the manifest file I actually need to parse.The following code shows my attempt to use XML::LibXML to drill down to the title tag:\[code\]use XML::LibXML;$filename = "imsmanifest.xml";$parser = XML::LibXML->new();$xmldoc = $parser->parse_file($filename);for my $sample ($xmldoc->findnodes('/manifest/organizations/organization/item/title')) { for my $property ($sample->findnodes('./*')) { print $property->nodeName(), ": ", $property->textContent(), "\n"; } print "\n"; };\[/code\]How does one deal with the colon in the adlcp:masteryscore tag? Whenever I try to use this, I get an error - but maybe I'm not doing it right.Could someone please show me the correct way to drill down to adlcp:masteryscore?Thank you very much.
 
Back
Top