Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: XML::LibXML & namespaces

by Cow1337killr (Monk)
on Oct 05, 2016 at 00:38 UTC ( #1173296=note: print w/replies, xml ) Need Help??

in reply to Re^2: XML::LibXML & namespaces
in thread XML::LibXML & namespaces

In this case it brings back all the values at the same time, such as "value1value2value3value4" etc... for an element.

I will admit that I am a beginner with respect to XML, but I think you took a leap of the imagination and you lost me.

Here is the program:

#!/usr/bin/perl # perl file.xml XML::LibXML + & namespaces # From Re: XML::LibXML & na +mespaces by choroba on Oct 03, 2016 at 19:10 EDT use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => shift); my $xpc = 'XML::LibXML::XPathContext'->new($dom); my $rpt = 1; $xpc->registerNs("ns$rpt", ''); my $nsdevices = "//ns$rpt:device"; my @devices = $xpc->findnodes($nsdevices); say $_->getAttribute('timestamp') for @devices; # This prints: # 2016-01-01T00:00:00.000-00:00 __END__

Here is the input (which I had to make modifications to, in order to get the so-called "snippet" to work with E. Choroba's program.):

<?xml version='1.0' encoding='utf-8'?> <Notify xmlns:xsd="" xmlns:xsi="http:/ +/" xmlns="http://docs.oasis-open.or +g/wsn/b-2"> <NotificationMessage> <Topic Dialect=" +ple">TOPICNAME</Topic> <ProducerReference> <Address xmlns="">address</Address +> <Metadata xmlns=""> <ns2:MessageID xmlns:ns2="">msgid< +/ns2:MessageID> </Metadata> </ProducerReference> <Message> <ns1:rpt xmlns:ns1=""> <ns1:reportObject> <ns1:device timestamp="2016-01-01T00:00:00.000-00:00"> </ns1:device> </ns1:reportObject> </ns1:rpt> </Message> </NotificationMessage> </Notify>

I named the input file file.xml

Here is the output:


Sorry, but I see one value. Perhaps I am not playing with a full deck, i.e., you have a different input file than I have, and you are asking a question regarding output that you have obtained from your input file, but I can only guess what your input file looks like.

Anyhow, I was able to get E. Choroba's program to work on my machine which runs Strawberry Perl, and I have learned something from him, yet again.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173296]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2023-09-29 13:02 GMT
Find Nodes?
    Voting Booth?

    No recent polls found