-
I'm not understanding well how to parse an XML file with ~Mojo::DOM
that I tried to convert into a selector chain in
Surely I'm not understanding how the DOM is working, but is the above possible? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
Yes, and the CSS selector I placed is correct. |
Beta Was this translation helpful? Give feedback.
-
There are two ways to deal with namespaces in Mojo::DOM::CSS. Either you define the namespace and use it with use Mojo::Base -strict;
use Mojo::DOM;
my $file = join("\n",<DATA>);
my $dom = Mojo::DOM->new->xml(1)->parse($file);
$dom->find( q{yadda|doc > item}, yadda => 'xocs-ns' )->each(sub { say $_->text });
$dom->find( q{xocs\:doc > item} )->each(sub { say $_->text });
__DATA__
<xocs:doc xmlns:xocs="xocs-ns">
<item>hello</item>
<item>world</item>
</xocs:doc> |
Beta Was this translation helpful? Give feedback.
-
@Akron thanks, I was figuring out the error in my namespace selector, so I have to rewrite it as:
that's probably the best solution. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I figured out I need to use the |
Beta Was this translation helpful? Give feedback.
There are two ways to deal with namespaces in Mojo::DOM::CSS. Either you define the namespace and use it with
|
as described here - or you ignore the namespace and escape the colon (that way the namespace prefix is treated as being part of the tag).