Link to home
Start Free TrialLog in
Avatar of jaimehy
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</buildingBlockGroup>
            <files>
               <file id="00001" />
               <file id="00002" />
               <file id="00003" />
               ...
            </files>
         </buildingBlock>
         <buildingBlock id="222">
            <name>testname1</name>
            <buildingBlockGroup>group0</buildingBlockGroup>
            <files>
               <file id="00009" />
               <file id="00010" />
               <file id="00003" />
               <file id="00004" />
               ...
            </files>
         </buildingBlock>
         ...
      </buildingBlocks>
      <fileInfo>
         <files>
            <file id="00001" containsTranslatables="true" arch="mfc">
               <subpath>bin\fpl_str.exe</subpath>
               <language id="de-de" langType="source" lang="de-de" />
            </file>
            <file id="00002" containsTranslatables="true" arch="mfc">
               <subpath>bin\fpl_vdv.exe</subpath>
               <language id="de-de" langType="source" lang="de-de" />
            </file>
            <file id="00003" containsTranslatables="true" arch="java">
               <subpath>javalibs\de.ivu.mb.fpl.erh.jar</subpath>
               <language id="neutral" langType="source" lang="de-de" />
            </file>
            <file id="00008" containsTranslatables="true" arch="ISA">
               <subpath>dlg\fpl_afp.dlx</subpath>
               <language id="de-de" langType="source" lang="de-de" />
            </file>
            <file id="00009" containsTranslatables="false" 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.erh.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=""true""
    and (@arch=""java"" or @arch="mfc")]/@arch", etc.
Avatar of jaimehy
jaimehy

ASKER

Oops!

In the footnote above, marked with an asterix, I meant:

"/versionInfo/fileinfo/files/file[@id=""" & fileID & """ and @containstranslatables=""true""
    and (@arch=""java"" or @arch="mfc")]/@arch"
Avatar of jaimehy

ASKER

Or even:

"/versionInfo/fileinfo/files/file[@id=""" & fileID & """ and @containstranslatables=""true""
    and (@arch=""java"" or @arch=""mfc"")]/@arch"
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of jaimehy

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
Not a problem, glad I was able to help. ;=)