Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Complex conditional clause using XPathMavigator

Posted on 2007-08-09
5
Medium Priority
?
243 Views
Last Modified: 2013-11-05
Hi all,
I have an XML file as follows:
<?xml version="1.0" encoding="UTF-8"?>
<products>
      <product id="1">
            <name>testname</name>
            <productGroup>fpl</productGroup>
            <customers>
                  <customer>Bus Éireann</customer>
                  <customer>Dublin Bus</customer>
            </customers>
            <languages>
                  <language id="de-de" langType="source"/>
                  <language id="en-gb" langType="target"/>
                  <language id="fr-fr" langType="target"/>
                  <language id="it-it" langType="target"/>
            </languages>
            <files>
                  <filename tobetranslated="true" arch="mfc">..\bin\fpl_str.exe</filename>
                  <filename tobetranslated="true" arch="mfc">..\bin\fpl_vdv.exel</filename>
                  <filename tobetranslated="true" arch="java">..\javalibs\de.ivu.mb.fpl.erh.jar</filename>
                  <filename tobetranslated="true" arch="ISA">..\bin\fpl_abf.exe</filename>
                  <filename tobetranslated="true" arch="ISA">..\dlg\fpl_abf.dlg</filename>
            </files>
      </product>
      <product id="2">
            <name>testname2</name>
            <productGroup>fpl</productGroup>
            <customers>
                  <customer>Bus Éireann</customer>
                  <customer>Dublin Bus</customer>
            </customers>
            <languages>
                  <language id="de-de" langType="source"/>
                  <language id="en-gb" langType="target"/>
            </languages>
            <files>
                  <filename tobetranslated="true" arch="mfc">..\bin\fpl_pat.exe</filename>
                  <filename tobetranslated="true" arch="mfc">..\bin\fpl_vdv.dll</filename>
                  <filename tobetranslated="false" arch="mfc">..\bin\fpl_vdv.dll</filename>
            </files>
      </product>
</products>

I need to select the text strings in the all /products/product/files/filename nodes where:
a) the /products/product/files/filename attribute tobetranslated="true" and;
b) the ancestor products/product node contains a languages/language node whose id attribute="en-gb".

Could anyone give me an xpath expression that yields this result?

Thanks very much in advance,

Jaimehy
0
Comment
Question by:jaimehy
  • 3
  • 2
5 Comments
 

Author Comment

by:jaimehy
ID: 19660906
What I want to end up with is a list of all files needing to be translated into English (or whatever language it happens to be) for all products listed in the XML file.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 19660917
/products/product[languages/language/@id = 'en-gb']/files/filename[@tobetranslated = 'true']

cheers

Geert
0
 

Author Comment

by:jaimehy
ID: 19661037
Dim document As XPathDocument
        Dim xPath As XPathNavigator

        document = New XPathDocument("mbfilelist.xml")

        xPath = document.CreateNavigator

        Dim nodes As XPathNodeIterator = xPath.Select("/products/product[languages/language/@id=""en-gb""]/files/filename[@tobetranslated=""true""]")
        While nodes.MoveNext
            FormCreatePSLProject.TextBox1.Text = FormCreatePSLProject.TextBox1.Text & ControlChars.NewLine & nodes.Current.Value
        End While
0
 

Author Comment

by:jaimehy
ID: 19661068
Jeez Geert,

You're quick.

Thanks.  I've posted the full code I used in VB .Net

Best wishes,

Jaime
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19661213
welcome
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question