dotnet xml:
Hi
I'm looking to take an existing XML document, query for certain nodes, and 'recreate' the document with just the relevant nodes. I'm currently using XPath - I have established the pattern that returns the required child nodes from the document, but am struggling to find a good statergy for recreating the file
Here is an excert of my XML file
<resource_data><planets><planet name="Planet1"><resources><resource><name>Resource1</name><ut>463</ut></resource><resource><name>Resource2</name><ut>501</ut></resource></resources></planet><planet name="Planet2"><resources><resource><name>Resource2</name><ut>505</ut></resource></resources></planet></planets><resource_data>
An example XPath is
resource_data/planets/planet/resources/resource[ut > 500
My issues are as follows
1) XPath only returns the child nodes I require, whilst losing detail regarding the nodes ancestors. Can I rephrase the XPath to return also the nodes ancestors, (specifically the node names and structure, for re-build purposes), or is the nature of xpath such that it only returns the 'deepest' nodes
2) Ideally, I want to take the original xml file and effectively 'filter' the nodes to show only the ones returned by XPath. Or alternatively, re-create the file with the correct structure, (so a single XMLT file can be used for processing). However, I'd like to be sure that I collate the nodes into the correct structure, (ie. resource nodes are under the correct planet node, etc). Is there an easy way to do this, or will I need to design a process that does this for me, (ie. checks the depth of the XPath results, recreates nodes/document structure upto that point, 'inserts' the queried nodes, then closes elements if required)?
I feel as though what I'm trying to do is not especially unusual, I'm just struggling to find any examples. Surely taking an XML document, querying it, and returning the 'filtered' results is not particularly un-orthodox? Any advice you could offer on stratergies for this solution would be greatly appreciated, (or even just a link to a sample that does the same). I have a couple of solutions, they just seem a little unwieldy - maybe I'm just looking at this the wrong way
Many thanks in advance for help... Please let me know if you require more detail or clarification
Jim