I'm having an issue parsing this XML file using either XML::LibXML or XML::Simple
<?xml version="1.0" encoding="utf-8"?> <GfmDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml +ns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="urn:us: +org:my:gfmdi:v35GfmDocument353.xsd" d1p1:DESVersion="5" d1p1:resource +Element="true" d1p1:createDate="2013-10-08" d1p1:classification="U" d1p1:ownerProduce +r="USA" xmlns:d1p1="urn:us:org:ic:ism" xmlns="urn:us:org:my:gfmdi:v35 +"> <GfmHeader> <TopicName>gfm_di.org_tree.usa</TopicName> <TopicMessageType>Baseline</TopicMessageType> <TopicMessageID>2754</TopicMessageID> <AsOfIncrementalMessageID>2754</AsOfIncrementalMessageID> </GfmHeader> <GFMIEDM35> <OBJ_ITEM_OO_TBL> <OBJ_ITEM d1p1:classification="U" d1p1:ownerProducer="USA"> <OBJ_ITEM_ID>72060793789255493</OBJ_ITEM_ID> <CAT_CODE>OR</CAT_CODE> <NAME_TXT>Oranization 10</NAME_TXT> <GFM_OBJ_ITEM_S_DTG>2008-10-01T00:00:00Z</GFM_OBJ_ITEM_S_DTG> <GFM_OBJ_ITEM_T_DTG>2999-12-01T00:00:00Z</GFM_OBJ_ITEM_T_DTG> <ORG> <ORG_ID>72060793789255493</ORG_ID> <CAT_CODE>UN</CAT_CODE> <GFM_CAT_CODE>NOS</GFM_CAT_CODE> </ORG> </OBJ_ITEM> <OBJ_ITEM d1p1:classification="U" d1p1:ownerProducer="USA"> <OBJ_ITEM_ID>72060793789255508</OBJ_ITEM_ID> <CAT_CODE>OR</CAT_CODE> <NAME_TXT>Organization 25</NAME_TXT> <GFM_OBJ_ITEM_S_DTG>2008-10-01T00:00:00Z</GFM_OBJ_ITEM_S_DTG> <GFM_OBJ_ITEM_T_DTG>2999-12-01T00:00:00Z</GFM_OBJ_ITEM_T_DTG> <ORG> <ORG_ID>72060793789255508</ORG_ID> <CAT_CODE>UN</CAT_CODE> <GFM_CAT_CODE>NOS</GFM_CAT_CODE> </ORG> </OBJ_ITEM> <OBJ_ITEM d1p1:classification="U" d1p1:ownerProducer="USA"> <OBJ_ITEM_ID>72060793789255510</OBJ_ITEM_ID> <CAT_CODE>OR</CAT_CODE> <NAME_TXT>Organization 50</NAME_TXT> <GFM_OBJ_ITEM_S_DTG>2008-10-01T00:00:00Z</GFM_OBJ_ITEM_S_DTG> <GFM_OBJ_ITEM_T_DTG>2999-12-01T00:00:00Z</GFM_OBJ_ITEM_T_DTG> <ORG> <ORG_ID>72060793789255510</ORG_ID> <CAT_CODE>UN</CAT_CODE> <GFM_CAT_CODE>NOS</GFM_CAT_CODE> </ORG> </OBJ_ITEM> </OBJ_ITEM_OO_TBL> </GFMIEDM35> </GfmDocument>
Here is code I'm using...no errors, but does not return anything.
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; my $filename = "aos_list.xml"; my $parser = XML::LibXML->new(); my $xmldoc = $parser->parse_file($filename); # tried different Xpath - still returns nothing for my $sample ($xmldoc->findnodes('/GfmDocument/GFMIEDM35/OBJ_ITEM_OO +_TBL/OBJ_ITEM')) { for my $property ($sample->findnodes('./*')) { print $property->nodeName(), ": ", $property->textContent(), " +\n"; } print "\n"; }
I'm trying to return: TopicMessageID OBJ_ITEM_ID CAT_CODE NAME_TXT ORG_ID CAT_CODE (from ORG) GFM_CAT_CODE Any suggestions?

In reply to Parsing XML by bayareamonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.