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

Accessing dotted tags with Mojo::DOM

by Fletch (Bishop)
on Dec 06, 2022 at 18:03 UTC ( [id://11148619]=perlquestion: print w/replies, xml ) Need Help??

Fletch has asked for the wisdom of the Perl Monks concerning the following question:

Other day was monkeying with something trying to parse and grobble through an XML file (specifically a jenkins task configuration file) using Mojo::DOM. The file parsed fine, and I can work my way down to the tag in question (com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty) using something like walking children on the parent element. However I'm presuming that the dots are being taken as CSS class names and neither find nor at will return the element node I'm trying to get. Tried a couple of "obvious" things like using \Q and manually backslashing the dots, and passing a regex qr// as well; neither to any avail.

This was a one-off excuse to play experiment with Mojo::DOM and I've since worked around using XML::Twig instead. That being said though I'm still curious if there'd be any way to do this with the former.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re: Accessing dotted tags with Mojo::DOM
by Haarg (Priest) on Dec 06, 2022 at 19:18 UTC
    $dom->at("com\\.cloudbees\\.hudson\\.plugins\\.folder\\.properties\\.A +uthorizationMatrixProperty")

      Well foo . . . I thought I’d tried that but it certainly works w/9.30. Serves me right first SoPW in 21 years and it’s PEBKAC.

      #!/usr/bin/env perl use 5.034; use Mojo::DOM; my $xml_src = do { local $/; <DATA>; }; my $dom = Mojo::DOM->new->xml(1); $dom->parse( $xml_src ); my @targets = ( qq{com\\.cloudbees\\.hudson\\.plugins\\.folder\\.proper +ties\\.AuthorizationMatrixProperty}, qq{\Qcom.cloudbees.hudson.plugins.folder.properties.Aut +horizationMatrixProperty}, ); for my $tgt (@targets) { say qq{tgt: $tgt}; say $dom->at( $tgt )->all_text; } exit 0; __END__ <?xml version="1.0" encoding="UTF-8"?> <foo> <com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixP +roperty> <bar>Test text</bar> </com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrix +Property> </foo>

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11148619]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-19 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found