Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 # xml-libxml-ex1.pl perl xml-libxml-ex1.pl file.xml XML::LibXML + & namespaces # From http://www.perlmonks.org/?node_id=1173200 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", 'http://www.url.com/path/for/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="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http:/ +/www.w3.org/2001/XMLSchema-instance" xmlns="http://docs.oasis-open.or +g/wsn/b-2"> <NotificationMessage> <Topic Dialect="http://docs.oasis-open.org/wsn/t-1/TopicExpression/Sim +ple">TOPICNAME</Topic> <ProducerReference> <Address xmlns="http://www.w3.org/2005/08/addressing">address</Address +> <Metadata xmlns="http://www.w3.org/2005/08/addressing"> <ns2:MessageID xmlns:ns2="http://www.w3.org/2005/08/addressing">msgid< +/ns2:MessageID> </Metadata> </ProducerReference> <Message> <ns1:rpt xmlns:ns1="http://www.url.com/path/for/rpt"> <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:

2016-01-01T00:00:00.000-00:00

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.


In reply to Re^3: XML::LibXML & namespaces by Cow1337killr
in thread XML::LibXML & namespaces by breezykatt

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-28 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found