xmlStreamReader icon indicating copy to clipboard operation
xmlStreamReader copied to clipboard

xpath methods

Open remiheens opened this issue 10 years ago • 2 comments

Hi,

First, thx for your work, it helps me every day. But I've a problem, I want to use xpath functions but it doesn't work Can you confirm that functions doesn't run with your library ?

xpath example: "/xml/track[id/text()='2']"

<?xml version="1.0"?>
<xml>
    <track>
        <id>1</id>
        <path>song1.mp3</path>
        <title>Track 1 - Track Title</title>
    </track>
    <track>
        <id>2</id>
        <path>song2.mp3</path>
        <title>Track 2 - Track Title</title>
    </track>
    <track>
        <id>3</id>
        <path>song3.mp3</path>
        <title>Track 3 - Track Title</title>
    </track>
    <track>
        <id>4</id>
        <path>song4.mp3</path>
        <title>Track 4 - Track Title</title>
    </track>
</xml>

remiheens avatar Feb 25 '15 13:02 remiheens

Hi @remiheens ,

Glad to hear you're making good use of this library, it means a lot :-) Unfortunately we don't currently support XPath. The main reason for this is that XPath supports look-ahead and look-back, which means that in order to check a node we would have to load the entire XML structure into memory. The idea here is to keep memory to a minimum, only loading in the tags we need, so it's unlikely that XPath will be added in future.

If XPath is an absolute essential, the SimpleXML object is a very good substitute (more specifically, the xpath method) and is very well documented.

Hope this helps :-)

hobnob avatar Feb 25 '15 15:02 hobnob

Yep, I'm using SimpleXMLElement. Currently, I'm using xpath method on small document (~XXMo) but I'm looking for a method who keep memory to a minimum like you. 'cause I've some larger documents to parse (~XGo)

So, thx for your work.

remiheens avatar Feb 25 '15 16:02 remiheens