Skip to content

Commit f08ce46

Browse files
committed
Add .nodePath() example to docs/tests
1 parent dbf3803 commit f08ce46

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

docs/Node.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ The returned key value is useful as a key in hashes.
146146

147147
method nodePath() returns Str
148148

149-
This function is not specified for any DOM level: It returns a canonical structure based XPath for a given node.
149+
This function is not specified for any DOM level: It returns a canonical structure based XPath for a given node. For example:
150+
151+
```raku
152+
use LibXML::Document;
153+
use LibXML::Element;
154+
LibXML::Document:D $doc .= parse: :file<samples/dromeds.xml>;
155+
my LibXML::Element @humps = $doc.find: "//humps";
156+
say @humps[0].nodePath: # /dromedaries/species[1]/humps
157+
```
150158

151159
### method isBlank
152160

lib/LibXML/Node.rakumod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,15 @@ constant names, namely: `#text`, `#cdata-section`, `#comment`, `#document`,
217217
method nodePath() returns Str
218218
219219
This function is not specified for any DOM level: It returns a canonical
220-
structure based XPath for a given node.
220+
structure based XPath for a given node. For example:
221+
222+
=begin code :lang<raku>
223+
use LibXML::Document;
224+
use LibXML::Element;
225+
LibXML::Document:D $doc .= parse: :file<samples/dromeds.xml>;
226+
my LibXML::Element @humps = $doc.find: "//humps";
227+
say @humps[0].nodePath: # /dromedaries/species[1]/humps
228+
=end code
221229
222230
=head3 method isBlank
223231

lib/LibXML/SAX/Handler/XML.rakumod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use LibXML::SAX::Handler::SAX2;
2-
31
#| Build pure Raku XML documents using LibXML's SAX parser
4-
class LibXML::SAX::Handler::XML
5-
is LibXML::SAX::Handler::SAX2 {
2+
class LibXML::SAX::Handler::XML {
3+
4+
use LibXML::SAX::Handler::SAX2;
5+
also is LibXML::SAX::Handler::SAX2;
66

77
# This class Builds a Raku 'XML' document,
88

t/08findnodes.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ subtest 'findnodes basic', {
3939

4040
@slist = $node.findnodes('./humps');
4141
is +@slist, 1, 'self path on relative name';
42+
is @slist[0].nodePath, '/dromedaries/species[1]/humps';
43+
is @slist[0]<text()>[0].nodePath, '/dromedaries/species[1]/humps/text()';
4244

4345
# find a single node
4446
@list = $elem.findnodes( "species[\@name='Llama']" );

0 commit comments

Comments
 (0)