bayareamonk has asked for the wisdom of the Perl Monks concerning the following question:
Here is code I'm using...no errors, but does not return anything.<?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>
I'm trying to return: TopicMessageID OBJ_ITEM_ID CAT_CODE NAME_TXT ORG_ID CAT_CODE (from ORG) GFM_CAT_CODE Any suggestions?#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing XML
by runrig (Abbot) on Oct 29, 2013 at 17:55 UTC | |
|
Re: Parsing XML with a Twig
by Discipulus (Canon) on Oct 30, 2013 at 09:14 UTC |