Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-10

Proposal for a XPath Namespace Resolver

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Daniel Gaspary

(Let me know if bugtracker is better to discuss the idea)

Today the XPath Ns Resolver is marked as "Experimental" and is just an alias for TDomNode:

TXPathNSResolver = TDOMNode {!!! experimental}; [1]

The problem happens when the Namespace definition is not at the root of the XML being processed:

<root>
<u1:e1 xmlns:u1="URI-1" u1:AnAttribute="AttValue"/> <u2:e2 xmlns:u2="URI-2"/>
</root>

Using....

    EvaluateXPathExpression('', x.DocumentElement,
   x.DocumentElement);

(x is a TXmlDocument)

Will raise an Exception due to the "Resolver" not being capable of finding the URI when starting from root.

I think of something simple as:

TXPathNSResolver = class

   property CurrentNode: TDomNode; //Necessary??
   property xml: TXmlDocument;
   property OnNeedUri: TXPathNeedUriEvent;
end;

TXPathNeedUriEvent would be something like:

procedure (Sender: TXPathNSResolver; out AUri: String) of object;

Searching and, if not found,
using OnNeedUri.

Ideas?

Should I post it at mantis, change, quit.. ?

[1] Line #352: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-xml/src/xpath.pp?view=markup

Reply by email

Daniel Gaspary
to Benito van der Zander: Alternatively, just use the XPath implementation of my Internet Tools…
Benito van der Zander wrote 8 lines
Alternatively, just use the XPath implementation of my Internet Tools (http://www.benibela.de/sources_en.html#internettools). Works perfectly there. E.g. process('<root> <u1:e1 xmlns:u1="URI-1" u1:AnAttribute="AttValue"/> <u2:e2 xmlns:u2="URI-2"/> </root>', '' ).toString returns 'AttValue'

It's not an could be useful to test and compare results.

Thank you.

Reply by email

Benito van der Zander
to Daniel Gaspary: (Let me know if bugtracker is better to discuss the idea) Today the XPath Ns Resolver is…

Alternatively, just use the XPath implementation of my Internet Tools (http://www.benibela.de/sources_en.html#internettools).

Works perfectly there.

E.g. process('<root> <u1:e1 xmlns:u1="URI-1" u1:AnAttribute="AttValue"/> <u2:e2 xmlns:u2="URI-2"/> </root>', '' ).toString
returns 'AttValue'

Daniel Gaspary wrote 50 lines
(Let me know if bugtracker is better to discuss the idea) Today the XPath Ns Resolver is marked as "Experimental" and is just an alias for TDomNode: TXPathNSResolver = TDOMNode {!!! experimental}; [1] The problem happens when the Namespace definition is not at the root of the XML being processed: <root> <u1:e1 xmlns:u1="URI-1" u1:AnAttribute="AttValue"/> <u2:e2 xmlns:u2="URI-2"/> </root> Using.... EvaluateXPathExpression('', x.DocumentElement, x.DocumentElement); (x is a TXmlDocument) Will raise an Exception due to the "Resolver" not being capable of finding the URI when starting from root. I think of something simple as: TXPathNSResolver = class property CurrentNode: TDomNode; //Necessary?? property xml: TXmlDocument; property OnNeedUri: TXPathNeedUriEvent; end; TXPathNeedUriEvent would be something like: procedure (Sender: TXPathNSResolver; out AUri: String) of object; Searching and, if not found, using OnNeedUri. Ideas? Should I post it at mantis, change, quit.. ? [1] Line #352: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-xml/src/xpath.pp?view=markup _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email