Hello!
I have an XML file which its content can't be altered as a source. My
solution should be able to produce some kind of pointers (in a seperate file)
to specific nodes (or even attributes\values) in the source XML file.
The source file contains many different namespaces (along with defaults).
The output file later will need to be processed and rewrite sections of the
XML source file by using the pointers ...
What do you think is the best approach for this problem? one solution is to
create a file containing a list of XPath queries - The problem is that XPath
in its nature can't promise unique results (not all of my source nodes has
unique id)
As the source file won't be altered, you can create XPath queries that
match only exactly one node.
I implemented part of XPointer in Javascript and the way I created
unique pointers was:
You start at a specific node. You walk the tree up until you are at the
root node or a node with an ID. As you walk the tree, you count the
siblings of the current node with the same name and save its name and
position.
For example:
<root>
<el id="a">
<a />
<b />
<b>
<c attr="value" />
</b>
</el>
</root>
1. start at attr: @attr
2. go to parent, wich is the only <c/> Element: c/@attr
3. go to parent, wich is the second <b/> Element: b[2]/c/@attr
4. go to parent, wich has an ID: id('a')/b[2]/c/@attr
Namespaces are no problem, the easiest way is to use the same prefixes
everywhere so you just have to save the XPath string. (Mvp.Xml includes
support for XPointer wich allows you to save the Namespaces together
with the path: "xmlns(a=url)xmlns(b=url)xpath1(a:path/b:...)")
--
Pascal Schmitt