Reading only a specific portion of XML file.

  • Thread starter Savvoulidis Iordanis
  • Start date
S

Savvoulidis Iordanis

I created the following test XML file, containing the translations of all my
reports's labels in all available languages. Every report has all its
localized texts under the proper CultureID node, under the report's name. The
question is, (as I'm new to XML/XPath/etc...) using ASP.NET(VB), how to read
all the labels of a report in a specified language, into a dataset? Imagine
that for a report (e.g. Report_A) the user selects the CultureID from a
dropdown list, to display the proper translations.


<?xml version="1.0" encoding="utf-8" ?>
<ReportTranslations>
<Report_A>
<el-GR>
<Control Name="lbl_1" Text="AAA" FormatString=""/>
<Control Name="lbl_2" Text="BBB" FormatString=""/>
<Control Name="lbl_3" Text="ΓΓΓ" FormatString=""/>
</el-GR>
<en-US>
<Control Name="lbl_1" Text="AAA" FormatString=""/>
<Control Name="lbl_2" Text="BBB" FormatString=""/>
<Control Name="lbl_3" Text="CCC" FormatString=""/>
</en-US>
</Report_A>

<Report_B>
<el-GR>
<Control Name="lbl_4" Text="ΔΔΔ" FormatString=""/>
<Control Name="lbl_5" Text="ΕΕΕ" FormatString=""/>
<Control Name="lbl_6" Text="ΖΖΖ" FormatString=""/>
</el-GR>
<en-US>
<Control Name="lbl_4" Text="DDD" FormatString=""/>
<Control Name="lbl_5" Text="EEE" FormatString=""/>
<Control Name="lbl_6" Text="FFF" FormatString=""/>
</en-US>
</Report_B>

</ReportTranslations>
 
G

Guest

I created the following test XML file, containing the translations of all my
reports's labels in all available languages. Every report has all its
localized texts under the proper CultureID node, under the report's name. The
question is, (as I'm new to XML/XPath/etc...) using ASP.NET(VB), how to read
all the labels of a report in a specified language, into a dataset? Imagine
that for a report (e.g. Report_A) the user selects the CultureID from a
dropdown list, to display the proper translations.

<?xml version="1.0" encoding="utf-8" ?>
<ReportTranslations>
    <Report_A>
        <el-GR>
            <Control Name="lbl_1" Text="AAA" FormatString=""/>
            <Control Name="lbl_2" Text="BBB" FormatString=""/>
            <Control Name="lbl_3" Text="ΓΓΓ" FormatString=""/>
        </el-GR>
        <en-US>
            <Control Name="lbl_1" Text="AAA" FormatString=""/>
            <Control Name="lbl_2" Text="BBB" FormatString=""/>
            <Control Name="lbl_3" Text="CCC" FormatString=""/>
        </en-US>
    </Report_A>

    <Report_B>
        <el-GR>
            <Control Name="lbl_4" Text="ΔΔΔ" FormatString=""/>
            <Control Name="lbl_5" Text="ΕΕΕ" FormatString=""/>
            <Control Name="lbl_6" Text="ΖΖΖ" FormatString=""/>
        </el-GR>
        <en-US>
            <Control Name="lbl_4" Text="DDD" FormatString=""/>
            <Control Name="lbl_5" Text="EEE" FormatString=""/>
            <Control Name="lbl_6" Text="FFF" FormatString=""/>
        </en-US>
    </Report_B>

</ReportTranslations>

Dim ds As New DataSet()
Dim xDoc As New XmlDocument()

'Load the contents of the file to our XmlDocument object
xDoc.LoadXml(File.ReadAllText(Request.PhysicalApplicationPath &
"XMLFile1.xml"))

'Select XML Node you need (e.g. for Report_A/el-GR)
Dim xn As XmlNode = xDoc.SelectSingleNode("//ReportTranslations/
Report_A/el-GR")

'Load the xml data in the XmlDocument object to the Dataset
ds.ReadXml(New XmlNodeReader(xn))
 
S

Savvoulidis Iordanis

Thanks Alexey. It worked!

I noticed that up to date, you've answered a lot of my posts. Thanks!

Iordanis
Greece
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top