|
 |
aspx thread: Accessing XML Attributes using C#
Message #1 by "Dean Santillan" <webmaster@5...> on Sat, 11 May 2002 12:28:10
|
|
Hi,
I am trying to get the innertext value of an attribute named Value where
the langagbe attribute is equal to the session language variable. I know
my code is wrong as this is the first time i have played with xml. it is
filling the labels fine but is always filling it with the japanese
language text. How can i get the the correct
value out according to the language needed?
All the ?????????? are supposed to be japanese languagbe text.
this is a snippet of my code
foreach (XmlNode anode in doc["webpage"])
{
Control c = targetPage.FindControl
(pageName).FindControl(anode.Name);
if (c != null)
{
switch ( c.GetType().ToString() )
{
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes
["Value"].InnerText;
break;
here is a snippet of my xml file
<webpage>
<ControlTitle Language="English" Value="Seeker Registration" />
<ControlTitle Language="Japanese" Value="???????" />
<InstructionText Language="English" Value="Membership is free as a
job seeker to Careers Japan. To successfully joinb the network, please
fill in the form below. Please note that all fiels are required to
successfully register." />
<InstructionText Language="Japanese" Value="????????????" />
</webpage>
Thanks
Dean
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Mon, 13 May 2002 09:26:12 -0400
|
|
Dean,
There are several ways that I can think of (although have never
implemented or came close to implementing) to work with multiple languages
with XML and ASP.NET. I think the recommended method is to use some
language attribute or what not in the
<?xml version="1.0" encoding=""?>
tag at the top of your XML file. You'd have to do some research, but the
language attribute could be something like "en-US" or whatever you wanted,
then programmatically you'd open the XML file for a particular language (of
course the entire language thing is moot because you'd have to know the
proper file name and what not).
Now the reason why I mention the above is because from what I have
looked at, the .NET framework has excellent support for cross language
application development and you should be able to use that to your
advantage. I'm curious to know which cross language features you have made
use of; perhaps with that knowledge some of us on the list can help you even
more.
I'm also curious to your XML format. I'm a bit confused on how you
define each control... is it literally "Label" that goes in the place of
"ControlTitle"? If so, you might want to consider:
<control type="System.Web.UI.WebControls.Label" language="en-us"
value="Seeker Registration" />
rather than <label language="English" value="..." />.
I say this because I think that by using XSLT you will find you
might have an easier time of doing alot of stuff you're writing logic for.
If you were to switch to "en-us" or "jp-jp" or whatever it is for your
language attributes, then you can get the language header the browser is
asking for and by using XSLT you can get the proper control(s) for the
proper language. You'll see that if you pull this off correctly, the
application would nearly write itself - don't underestimate what you can do
with XML and XSLT!
As to your problem, you're never actually looking for a particular
language or comparing to a session variable. Unless there's some magic I
don't know about with ASP.NET and Session[], you need to code this logic.
Something like:
(under the foreach ... statement:)
if (anode.Attributes["Language"].Equals(Session["Language"]))
{
Control c = ...
}
Finally, the recommended way to get a control's type in C# is to use
the language operator "typeof", i.e.
switch (typeof(c))
{
case System.Web.UI.WebControls.Label:
...;
break;
}
This is because the .GetType() object method requires the use of reflection,
whereas typeof() apparently can analyze an object variable or value type to
determine exactly what it is. typeof() is faster.
HTH,
- Chuck
-----Original Message-----
From: Dean Santillan [mailto:webmaster@5...]
Sent: Saturday, May 11, 2002 8:28 AM
To: ASP+
Subject: [aspx] Accessing XML Attributes using C#
Hi,
I am trying to get the innertext value of an attribute named Value where
the langagbe attribute is equal to the session language variable. I know
my code is wrong as this is the first time i have played with xml. it is
filling the labels fine but is always filling it with the japanese
language text. How can i get the the correct
value out according to the language needed?
All the ?????????? are supposed to be japanese languagbe text.
this is a snippet of my code
foreach (XmlNode anode in doc["webpage"])
{
Control c = targetPage.FindControl
(pageName).FindControl(anode.Name);
if (c != null)
{
switch ( c.GetType().ToString() )
{
case "System.Web.UI.WebControls.Label":
Label lb = (Label) c;
lb.Text = anode.Attributes
["Value"].InnerText;
break;
here is a snippet of my xml file
<webpage>
<ControlTitle Language="English" Value="Seeker Registration" />
<ControlTitle Language="Japanese" Value="???????" />
<InstructionText Language="English" Value="Membership is free as a
job seeker to Careers Japan. To successfully joinb the network, please
fill in the form below. Please note that all fiels are required to
successfully register." />
<InstructionText Language="Japanese" Value="????????????" />
</webpage>
Thanks
Dean
|
|
 |