jaimehy
asked on
Searching for nodes using id attributes using xpathnavigator
Hi all,
I'm developing an automated localisation system in VB .NET, and I'm using an XML file for some of my parameters.
The following is a simplified version of the XML file I'm using:
<?xml version="1.0" encoding="UTF-8" ?>
<versionInfo>
<buildingBlocks>
<buildingBlock id="1">
<name>testname0</name>
<buildingBlockGroup>group0 </building BlockGroup >
<files>
<file id="00001" />
<file id="00002" />
<file id="00003" />
...
</files>
</buildingBlock>
<buildingBlock id="222">
<name>testname1</name>
<buildingBlockGroup>group0 </building BlockGroup >
<files>
<file id="00009" />
<file id="00010" />
<file id="00003" />
<file id="00004" />
...
</files>
</buildingBlock>
...
</buildingBlocks>
<fileInfo>
<files>
<file id="00001" containsTranslatables="tru e" arch="mfc">
<subpath>bin\fpl_str.exe</ subpath>
<language id="de-de" langType="source" lang="de-de" />
</file>
<file id="00002" containsTranslatables="tru e" arch="mfc">
<subpath>bin\fpl_vdv.exe</ subpath>
<language id="de-de" langType="source" lang="de-de" />
</file>
<file id="00003" containsTranslatables="tru e" arch="java">
<subpath>javalibs\de.ivu.m b.fpl.erh. jar</subpa th>
<language id="neutral" langType="source" lang="de-de" />
</file>
<file id="00008" containsTranslatables="tru e" arch="ISA">
<subpath>dlg\fpl_afp.dlx</ subpath>
<language id="de-de" langType="source" lang="de-de" />
</file>
<file id="00009" containsTranslatables="fal se" arch="MFC">
<subpath>dlg\fpl_afp.dll</ subpath>
<language id="de-de" langType="source" lang="de-de" />
</file>
...
</files>
</fileInfo>
</versionInfo>
For example, one of the things I want to do is retrieve some information from an individual /versionInfo/files/file node, on condition that its @arch value is either "java" or "mfc", and that its @containsTranslatables value is "true".
I need the following information:
1. @arch attribute
2. subpath element value
3. language/@id and
4. language/@lang
A search of file id="00003", for example, should yield a string array like this:
StringArray(0) -> "java"
StringArray(1) -> "javalibs\de.ivu.mb.fpl.er h.jar"
StringArray(2) ->"neutral"
StringArray(3) -> "de-de"
A search of file id="00009" should yield nothing.
Do I need four different XPath expressions*, each called separately from an XPath navigator, or can I do it more elegantly?
What is the best VB .NET class to use to implement the solution? Should I use XPathNavigator? And if so, what methods should I use?
Thanks very much in advance,
JaimeHy
* Something like this?:
"/versionInfo/files/file[@ id=""" & fileID & """ and @containstranslatables=""t rue""
and (@arch=""java"" or @arch="mfc")]/@arch", etc.
I'm developing an automated localisation system in VB .NET, and I'm using an XML file for some of my parameters.
The following is a simplified version of the XML file I'm using:
<?xml version="1.0" encoding="UTF-8" ?>
<versionInfo>
<buildingBlocks>
<buildingBlock id="1">
<name>testname0</name>
<buildingBlockGroup>group0
<files>
<file id="00001" />
<file id="00002" />
<file id="00003" />
...
</files>
</buildingBlock>
<buildingBlock id="222">
<name>testname1</name>
<buildingBlockGroup>group0
<files>
<file id="00009" />
<file id="00010" />
<file id="00003" />
<file id="00004" />
...
</files>
</buildingBlock>
...
</buildingBlocks>
<fileInfo>
<files>
<file id="00001" containsTranslatables="tru
<subpath>bin\fpl_str.exe</
<language id="de-de" langType="source" lang="de-de" />
</file>
<file id="00002" containsTranslatables="tru
<subpath>bin\fpl_vdv.exe</
<language id="de-de" langType="source" lang="de-de" />
</file>
<file id="00003" containsTranslatables="tru
<subpath>javalibs\de.ivu.m
<language id="neutral" langType="source" lang="de-de" />
</file>
<file id="00008" containsTranslatables="tru
<subpath>dlg\fpl_afp.dlx</
<language id="de-de" langType="source" lang="de-de" />
</file>
<file id="00009" containsTranslatables="fal
<subpath>dlg\fpl_afp.dll</
<language id="de-de" langType="source" lang="de-de" />
</file>
...
</files>
</fileInfo>
</versionInfo>
For example, one of the things I want to do is retrieve some information from an individual /versionInfo/files/file node, on condition that its @arch value is either "java" or "mfc", and that its @containsTranslatables value is "true".
I need the following information:
1. @arch attribute
2. subpath element value
3. language/@id and
4. language/@lang
A search of file id="00003", for example, should yield a string array like this:
StringArray(0) -> "java"
StringArray(1) -> "javalibs\de.ivu.mb.fpl.er
StringArray(2) ->"neutral"
StringArray(3) -> "de-de"
A search of file id="00009" should yield nothing.
Do I need four different XPath expressions*, each called separately from an XPath navigator, or can I do it more elegantly?
What is the best VB .NET class to use to implement the solution? Should I use XPathNavigator? And if so, what methods should I use?
Thanks very much in advance,
JaimeHy
* Something like this?:
"/versionInfo/files/file[@
and (@arch=""java"" or @arch="mfc")]/@arch", etc.
ASKER
Or even:
"/versionInfo/fileinfo/fil es/file[@i d=""" & fileID & """ and @containstranslatables=""t rue""
and (@arch=""java"" or @arch=""mfc"")]/@arch"
"/versionInfo/fileinfo/fil
and (@arch=""java"" or @arch=""mfc"")]/@arch"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The tbID.Text is a text box used to identify the file in question. It can be any text field that identifies the file you wish to search for.
ASKER
Much obliged FernandoSoto,
I've put together a far less elegant solution since then, but I'll update it with your suggestion.
Thanks both for the speed and the thoroughness.
JaimeHy
I've put together a far less elegant solution since then, but I'll update it with your suggestion.
Thanks both for the speed and the thoroughness.
JaimeHy
Not a problem, glad I was able to help. ;=)
ASKER
In the footnote above, marked with an asterix, I meant:
"/versionInfo/fileinfo/fil
and (@arch=""java"" or @arch="mfc")]/@arch"