XML problem

B

Balint Toth

Hi,

I read an XML document with the following code:

const String filename = "probe.xml";
XmlTextReader reader = new XmlTextReader(filename);
bool masodik = false;

while (reader.Read()==true)
{
switch (reader.Name)
{
case "Title":
reader.Read();
if (!masodik)
{
myList.Items.Add(reader.Value);
}
masodik = !masodik;
break;
}
}
reader.Close();

The XML file containt something like:

<Title>mytitle</Title>
<Item>First entry</Item>
<Item>2nd entry</Item>
<Item>3rd entry</Item>
<Item>4th entry</Item>
<Item>5th entry</Item>

If I put an accent letter in the XML:

<Title>mytitle õúûóüúáéí</Title>
<Item>First entry</Item>
....

the application exist with some error message (not exception).

What can be the problem?

Best regards,
Bálint Tóth
 
A

Alex Feinman [MVP]

You need to define appropriate encoding in your XML:
<?xml version="1.0" encoding="UTF-8"?> or other encoding which matches the
contents of your xml file. Make sure the xml file opens with Pocket IE
 
B

Balint Toth

My point is to open the XML from my app. I use XML as a database. But if I
add the line you wrote, the app still freezes.
 
Y

Y. Sivaram

As Alex indicated you need to try different encodings that is suitable for
your content. For example

<?xml version="1.0" encoding="windows-1252" ?>

Also the reason for opening the file in IE (Either in Pocket PC or in
Desktop) is, it will give a detailed parse error message with the reason for
failure.

Best Regards,
Y. Sivaram
 
B

Balint Toth

I got it! It`s ISO-8859-2. Thanks a lot! I didn't think the .NET will
autodetect the encoding... I tought I have to set it!

Thanks again!

Best regards,
Bálint Tóth
 

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

Top