11import {
22 XmlError ,
3- xmlHasNsProp ,
43 xmlGetNsList ,
4+ xmlHasNsProp ,
55 XmlNamedNodeStruct ,
66 xmlNodeGetContent ,
77 XmlNodeSetStruct ,
88 XmlNodeStruct ,
99 XmlNsStruct ,
1010 xmlSearchNs ,
11+ xmlXPathCompiledEval ,
1112 xmlXPathFreeContext ,
1213 xmlXPathFreeObject ,
1314 xmlXPathNewContext ,
1415 XmlXPathObjectStruct ,
1516 xmlXPathRegisterNs ,
16- xmlXPathCompiledEval ,
1717 xmlXPathSetContextNode ,
1818} from './libxml2.mjs' ;
1919import type XmlDocument from './document.mjs' ;
2020import type { XmlNodePtr } from './libxml2raw.js' ;
21- import XmlXPath from './xpath.mjs' ;
22-
23- /**
24- * Map between the prefix and the uri of the namespace
25- */
26- export interface NamespaceMap {
27- [ prefix : string ] : string ;
28- }
21+ import { XmlXPath , NamespaceMap } from './xpath.mjs' ;
2922
3023export abstract class XmlNode {
3124 protected _doc : XmlDocument ;
@@ -156,6 +149,9 @@ export abstract class XmlNode {
156149 return ns ? XmlNsStruct . href ( ns ) : null ;
157150 }
158151
152+ get ( xpath : XmlXPath ) : XmlNode | null ;
153+ get ( xpath : string , namespaces ?: NamespaceMap ) : XmlNode | null ;
154+ get ( xpath : string | XmlXPath , namespaces ?: NamespaceMap ) : XmlNode | null ;
159155 /**
160156 * Find the first descendant node matching the given xpath selector
161157 *
@@ -186,18 +182,18 @@ export abstract class XmlNode {
186182 }
187183
188184 private xpathEval ( xpath : string | XmlXPath , namespaces ?: NamespaceMap ) {
189- const xpathCompiled = xpath instanceof XmlXPath ? xpath : new XmlXPath ( xpath ) ;
190- const ret = this . compiledXPathEval ( xpathCompiled , namespaces ) ;
185+ const xpathCompiled = xpath instanceof XmlXPath ? xpath : new XmlXPath ( xpath , namespaces ) ;
186+ const ret = this . compiledXPathEval ( xpathCompiled ) ;
191187 if ( ! ( xpath instanceof XmlXPath ) ) {
192188 xpathCompiled . dispose ( ) ;
193189 }
194190 return ret ;
195191 }
196192
197- private compiledXPathEval ( xpath : XmlXPath , namespaces ?: NamespaceMap ) {
193+ private compiledXPathEval ( xpath : XmlXPath ) {
198194 const context = xmlXPathNewContext ( this . _doc . _docPtr ) ;
199- if ( namespaces ) {
200- Object . entries ( namespaces )
195+ if ( xpath . _namespaces ) {
196+ Object . entries ( xpath . _namespaces )
201197 . forEach ( ( [ prefix , uri ] ) => {
202198 xmlXPathRegisterNs ( context , prefix , uri ) ;
203199 } ) ;
@@ -208,6 +204,9 @@ export abstract class XmlNode {
208204 return xpathObj ;
209205 }
210206
207+ find ( xpath : XmlXPath ) : XmlNode [ ] ;
208+ find ( xpath : string , namespaces ?: NamespaceMap ) : XmlNode [ ] ;
209+ find ( xpath : string | XmlXPath , namespaces ?: NamespaceMap ) : XmlNode [ ] ;
211210 /**
212211 * Find all the descendant nodes matching the given xpath selector.
213212 * @param xpath XPath selector
0 commit comments