[Expat-discuss] XPATH for expat?
Nick MacDonald
nickmacd at gmail.com
Fri Sep 28 16:50:38 CEST 2007
Mark:
I don't honestly know XPATH, but I presume your general idea is that
there would be some input config file to your program that would give
the path of the information that needs to be located, processed,
updated or whatever it is that your program does.
Assuming I understand your problem correctly, then this sounds like a
simple enough task without using something with a high overhead. All
you need to do is implement a small software stack (with push and pop
operations) and whenever you see an XML file event (start tag, end
tag) you push or pop as appropriate. Then you make a simple function
that can walk the stack and output a textual "path" which gives your
current location in the file (with a little creativity you could have
the stack operations maintain the current path in a string fairly
efficiently).
Now all you need is to get the current path for every start tag, and
find out if its one of the path's you supplied in your config file.
It may not be as "standards based" as XPATH would be, but it would
have the possibility of being very fast and low overhead. I have
already written such code, and its not very large... I really wish I
could share it, but my employer would frown on that.
Good luck,
Nick
On 28 Sep 2007 09:17:52 -0000, Mark <11mjazbdg02 at sneakemail.com> wrote:
> Does anyone know of a simple XPATH wrapper for expat? The reason is
> that I need to implement a parser and the schema is likely to change
> in the future so I don't want to hardcode too much.
>
> All I need to do is extract a few pieces of text from an XML document.
--
Nick MacDonald
NickMacD at gmail.com
More information about the Expat-discuss
mailing list