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.