Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Thursday, March 22, 2012

Newbie:sending German characters on TCP link

Hi,

I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine. Now
on a German OS, German characters were sent as question mark in the received
string. I guess that's because ASCII encoding was used and unicode encoding
should be used instead. But then would byte ordering(little endian ir big
endian) be a problem because the received TCP stream could be consumed by
both a Java and .NET clients ? What could be done to ensure that the
received unicode encoded XML stream be decoded by both .NET and Java clients
? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sample
anywhere ?

Thanks in advance and regards

NavinOn Feb 27, 7:44 pm, "Navin Mishra" <navin.mis...@.siemens.comwrote:

Quote:

Originally Posted by

Hi,
>
I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine. Now
on a German OS, German characters were sent as question mark in the received
string. I guess that's because ASCII encoding was used and unicode encoding
should be used instead. But then would byte ordering(little endian ir big
endian) be a problem because the received TCP stream could be consumed by
both a Java and .NET clients ? What could be done to ensure that the
received unicode encoded XML stream be decoded by both .NET and Java clients
? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sample
anywhere ?
>


This group is for ASP.NET

Regarding your problem

First of all, ensure that the xml is encoded

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

Quote:

Originally Posted by

>.........."


then set this encoding to the method which send the data.

For example

myWriter = New System.IO.StreamWriter(xmlRequest.GetRequestStream (),
Encoding.GetEncoding(1252))
myWriter.Write(sXML)

I used German code page 1252 here, but you can consider to use utf-8...
Thus wrote Navin,

Quote:

Originally Posted by

Hi,
>
I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine.
Now on a German OS, German characters were sent as question mark in
the received string. I guess that's because ASCII encoding was used
and unicode encoding should be used instead.


Absolutely. If not Unicode, then at least some 8 bit encoding like ISO Latin
1.

Quote:

Originally Posted by

But then would byte
ordering(little endian ir big endian) be a problem because the
received TCP stream could be consumed by both a Java and .NET clients
?


No. All UTF-16/32 variants include byte order marks that allow the receiver
to pick up the appropriate byte order, and UTF-8 is the same for both Big
Endian and Little Endian systems.

Quote:

Originally Posted by

What could be done to ensure that the received unicode encoded XML
stream be decoded by both .NET and Java clients ? And, which encoding
.NET class be used utf8, utf32,.. ? Is there a sample anywhere ?


If your XML contains mostly Latin characters, use UTF-8. That'll require
the least bandwidth. You can write an XML document to any stream using either
an XmlWriter or XmlDocument.Save().

Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

Newbie:sending German characters on TCP link

Hi,
I've a .NET application that sends XML string as bytes on a TCP
connection. It had used ASCII encoding so far and everything was fine. Now
on a German OS, German characters were sent as question mark in the received
string. I guess that's because ASCII encoding was used and unicode encoding
should be used instead. But then would byte ordering(little endian ir big
endian) be a problem because the received TCP stream could be consumed by
both a Java and .NET clients ? What could be done to ensure that the
received unicode encoded XML stream be decoded by both .NET and Java clients
? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sample
anywhere ?
Thanks in advance and regards
NavinOn Feb 27, 7:44 pm, "Navin Mishra" <navin.mis...@.siemens.com> wrote:
> Hi,
> I've a .NET application that sends XML string as bytes on a TCP
> connection. It had used ASCII encoding so far and everything was fine. Now
> on a German OS, German characters were sent as question mark in the receiv
ed
> string. I guess that's because ASCII encoding was used and unicode encodin
g
> should be used instead. But then would byte ordering(little endian ir big
> endian) be a problem because the received TCP stream could be consumed by
> both a Java and .NET clients ? What could be done to ensure that the
> received unicode encoded XML stream be decoded by both .NET and Java clien
ts
> ? And, which encoding .NET class be used utf8, utf32,.. ? Is there a sampl
e
> anywhere ?
>
This group is for ASP.NET
Regarding your problem
First of all, ensure that the xml is encoded
sXML = "<?xml version=""1.0"" encoding=""windows-1252""?
>.........."
then set this encoding to the method which send the data.
For example
myWriter = New System.IO.StreamWriter(xmlRequest.GetRequestStream(),
Encoding.GetEncoding(1252))
myWriter.Write(sXML)
I used German code page 1252 here, but you can consider to use utf-8...
Thus wrote Navin,

> Hi,
> I've a .NET application that sends XML string as bytes on a TCP
> connection. It had used ASCII encoding so far and everything was fine.
> Now on a German OS, German characters were sent as question mark in
> the received string. I guess that's because ASCII encoding was used
> and unicode encoding should be used instead.
Absolutely. If not Unicode, then at least some 8 bit encoding like ISO Latin
1.

> But then would byte
> ordering(little endian ir big endian) be a problem because the
> received TCP stream could be consumed by both a Java and .NET clients
> ?
No. All UTF-16/32 variants include byte order marks that allow the receiver
to pick up the appropriate byte order, and UTF-8 is the same for both Big
Endian and Little Endian systems.

> What could be done to ensure that the received unicode encoded XML
> stream be decoded by both .NET and Java clients ? And, which encoding
> .NET class be used utf8, utf32,.. ? Is there a sample anywhere ?
If your XML contains mostly Latin characters, use UTF-8. That'll require
the least bandwidth. You can write an XML document to any stream using eithe
r
an XmlWriter or XmlDocument.Save().
Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

Friday, March 16, 2012

Newline in a multiline-textbox filled by a DataList?

I'm binding my Data to the Datalist like that:

// Opening standard XML text reader
System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader(Server.MapPath("~/xml/guestbook.xml"));
DataSet myDataSet = new DataSet();
// Reading XML into a dataset
myDataSet.ReadXml(myXmlReader);
myXmlReader.Close();

// Bind data to the data list!
GuestbookData.DataSource = myDataSet.Tables[0];
GuestbookData.DataBind();

then I read it out like that:

<div class="author"><a href="http://links.10026.com/?link=http://<%# DataBinder.Eval(Container.DataItem, "url") %>" target="_blank"><%# DataBinder.Eval(Container.DataItem, "name") %></a> schrieb am <%# DataBinder.Eval(Container.DataItem, "date") %> </div>
<div class="text"><%# DataBinder.Eval(Container.DataItem, "entry_Text") %></div>

Now I'd like to translate NewLines a User made when he was writing a comment into <br>s because right now, such a text:

writing something

and something else

is shown as writing something and something else. (In just one line without the linebreak).

How to translate those breaks? Thanks!

Change:
<div class="text"><%# DataBinder.Eval(Container.DataItem, "entry_Text") %></div>
to:
<div class="text"><%# ReplaceCRLF(DataBinder.Eval(Container.DataItem, "entry_Text")) %></div>
and then have a function in your page called ReplaceCRLF:
string ReplaceCRLF(string val)
{
return val.Replace(System.Environment.NewLine, "<br/>");
}
-Brock

Thanks, that's working!

News content to XML file

Hello,
I have been given a task for creating a utility (asp.net/vb.net) exe which
transaltes the news content
into an XML file.

Can some one give me any directions to how we need to do this?

ThanksWhy not consider syndicating your news as an RSS xml file. It will then at
least be in a format and structure easily deciphered.

http://aspnet.4guysfromrolla.com/articles/021804-1.aspx

--
Regards

John Timney (MVP)

"Karthik Natarajan" <nkarthik04@.gmail.com> wrote in message
news:Ok1N4qYkGHA.3816@.TK2MSFTNGP02.phx.gbl...
> Hello,
> I have been given a task for creating a utility (asp.net/vb.net) exe which
> transaltes the news content
> into an XML file.
> Can some one give me any directions to how we need to do this?
>
> Thanks
>