Reputation: 79468
I'm basically taking fileA.xml, grabbing nodes from totally distinct parts of the file, and building a new tree in fileB.xml. Relative paths are a bit confusing now because once I get to a node nested 3 down, and I need to add another node which is nested 4 down from a totally different branch, I start needing global xpaths.
Question is, which is better performing? Relative paths or global paths?
1) node3 (when I'm in node1/node2) 2) /node1/node2/node3
<node1a>
<node2a>
<node3a/>
<node3a/>
<node3a/>
</node2a>
<node2b>
<node3b>
<node4b/>
</node3b>
</node2b>
</node1a>
<!-- the above is rearranged to this -->
<node1a>
<node4b/>
<node3a/>
<node3a/>
<node3a/>
</node1a>
FileA.xml will always have the same structure, and the reusability of the xslt templates isn't an issue. So should I just use global paths?
Otherwise there's too much context to keep track of it seems.
Thanks a lot, Lance
Upvotes: 0
Views: 214
Reputation: 101665
For a trivial implementation, every step involving an element name is a string lookup; so the fewer, the better. Otherwise, it's very much implementation dependent. As well, relative paths are more idiomatic.
Upvotes: 3
Reputation: 7563
I am not an expert, but relative paths and global paths which don't use the * or // operator's should have the same performance.
Upvotes: 1
Reputation: 34573
I'd say don't worry about it for now. If your XML files become large enough for this to matter, you probably won't end up using XPath anyways since it needs the entire document to be loaded into memory.
Upvotes: 1