473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

specifying the encoding attribute explicitly

Hello,

Using code below to create an xml file, how do I specifiy utf-8 encoding in
the root element, ie create "<?xml version="1.0" encoding="utf-8"?>

Thanks!

-------------------------------------------

Dim xmlWriter As New
XmlTextWriter("C:\inetpub\wwwroot\rss2\20061019\te st.xml", Nothing)
xmlWriter.Formatting = Formatting.Indented

With xmlWriter
.WriteStartDocument()
.WriteStartElement("rss")
.WriteAttributeString("version", "2.0")
.WriteStartElement("channel")
.WriteElementString("title", "caseNumber" & ": " & "caseName")
.WriteElementString("link", "link")
.WriteElementString("description", "caseName")
.WriteElementString("lastBuildDate", Now.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") '<<<<<<<<<<<<<<<<<<<<<<<<<<<
'.WriteElementString("pubDate", caseAdded.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") 'Now())
.WriteStartElement("item")
.WriteElementString("title", "description")
.WriteStartElement("guid")
.WriteAttributeString("isPermaLink", Nothing, "false")
.WriteString(Guid.NewGuid.ToString)
.WriteEndElement()
' .WriteElementString("title", description)
.WriteElementString("description", "caseNumber")
.WriteElementString("link", "link")
'.WriteElementString("pubDate", dateModified & " 12:00:00 GMT")
'Now().ToString) <---------------------------change
.WriteElementString("pubDate", Now().ToString("ddd, dd MMM yyyy
hh:mm:ss") & " GMT")
.WriteEndElement() '<<<<<<<<<<<<<<<<<<<<<
.WriteEndElement()
.WriteEndElement()
.WriteEndDocument()
.Flush()
.Close()
End With
xmlWriter = Nothing

Oct 19 '06 #1
7 3479
Hi John,

I don't think <?xml version="1.0" encoding="utf-8"?is actually
supposed to be part of your XML document. Doesn't this XML directive
automatically get created by whatever mechanism you are using to
transmit the XML?

Usually, this is set by the content-type property (MIME type) of
whatever is actually performing the transmission.

Andy

Oct 19 '06 #2
Also, using the code below, I can't open the resulting xml file in IE7.0 and
it won't validate at www.feedvalidator.org unless I open it first in notepad
and then save it back. I make no changes to the file, I simply open and then
close it using notepad and then it validates in both. The file (before
opening/saving in notepad) will work in various rss readers, however, without
any error. Any ideas? Thanks!

"John Hopper" wrote:
Hello,

Using code below to create an xml file, how do I specifiy utf-8 encoding in
the root element, ie create "<?xml version="1.0" encoding="utf-8"?>

Thanks!

-------------------------------------------

Dim xmlWriter As New
XmlTextWriter("C:\inetpub\wwwroot\rss2\20061019\te st.xml", Nothing)
xmlWriter.Formatting = Formatting.Indented

With xmlWriter
.WriteStartDocument()
.WriteStartElement("rss")
.WriteAttributeString("version", "2.0")
.WriteStartElement("channel")
.WriteElementString("title", "caseNumber" & ": " & "caseName")
.WriteElementString("link", "link")
.WriteElementString("description", "caseName")
.WriteElementString("lastBuildDate", Now.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") '<<<<<<<<<<<<<<<<<<<<<<<<<<<
'.WriteElementString("pubDate", caseAdded.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") 'Now())
.WriteStartElement("item")
.WriteElementString("title", "description")
.WriteStartElement("guid")
.WriteAttributeString("isPermaLink", Nothing, "false")
.WriteString(Guid.NewGuid.ToString)
.WriteEndElement()
' .WriteElementString("title", description)
.WriteElementString("description", "caseNumber")
.WriteElementString("link", "link")
'.WriteElementString("pubDate", dateModified & " 12:00:00 GMT")
'Now().ToString) <---------------------------change
.WriteElementString("pubDate", Now().ToString("ddd, dd MMM yyyy
hh:mm:ss") & " GMT")
.WriteEndElement() '<<<<<<<<<<<<<<<<<<<<<
.WriteEndElement()
.WriteEndElement()
.WriteEndDocument()
.Flush()
.Close()
End With
xmlWriter = Nothing
Oct 19 '06 #3
I see now that this can be declared as a parameter of the constructor.

"John Hopper" wrote:
Hello,

Using code below to create an xml file, how do I specifiy utf-8 encoding in
the root element, ie create "<?xml version="1.0" encoding="utf-8"?>

Thanks!

-------------------------------------------

Dim xmlWriter As New
XmlTextWriter("C:\inetpub\wwwroot\rss2\20061019\te st.xml", Nothing)
xmlWriter.Formatting = Formatting.Indented

With xmlWriter
.WriteStartDocument()
.WriteStartElement("rss")
.WriteAttributeString("version", "2.0")
.WriteStartElement("channel")
.WriteElementString("title", "caseNumber" & ": " & "caseName")
.WriteElementString("link", "link")
.WriteElementString("description", "caseName")
.WriteElementString("lastBuildDate", Now.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") '<<<<<<<<<<<<<<<<<<<<<<<<<<<
'.WriteElementString("pubDate", caseAdded.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") 'Now())
.WriteStartElement("item")
.WriteElementString("title", "description")
.WriteStartElement("guid")
.WriteAttributeString("isPermaLink", Nothing, "false")
.WriteString(Guid.NewGuid.ToString)
.WriteEndElement()
' .WriteElementString("title", description)
.WriteElementString("description", "caseNumber")
.WriteElementString("link", "link")
'.WriteElementString("pubDate", dateModified & " 12:00:00 GMT")
'Now().ToString) <---------------------------change
.WriteElementString("pubDate", Now().ToString("ddd, dd MMM yyyy
hh:mm:ss") & " GMT")
.WriteEndElement() '<<<<<<<<<<<<<<<<<<<<<
.WriteEndElement()
.WriteEndElement()
.WriteEndDocument()
.Flush()
.Close()
End With
xmlWriter = Nothing
Oct 19 '06 #4

Well, I know that MS Notepad processes carriage returns and line feeds
differently than MS WordPad. I've seen this in UNIX generated files
that are opened in Notepad - all the line breaks are lost and instead
display as unprintable characters. But, when you open the same file in
MS WordPad, the line breaks are processed correctly.

I suspect that notepad just writes an ASC(13) carriage return for each
line break rather than the line feed/carriage return ASC(13)ASC(10)
combination (or is it the other way around?). When you save your file
in MS Notepad, the line terminator that is compatible with your other
applications is substituted into each of your file's original line
terminators that aren't compatible with your other applications.

BTW it could also be that the sequence of the terminator characters is
causing the problem (ie 10 followed by 13 or 13 followed by 10)

Andy

Oct 20 '06 #5
John Hopper wrote:
Using code below to create an xml file, how do I specifiy utf-8 encoding in
the root element, ie create "<?xml version="1.0" encoding="utf-8"?>
Dim xmlWriter As New
XmlTextWriter("C:\inetpub\wwwroot\rss2\20061019\te st.xml", Nothing)
See the documentation
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlTextWriterClassctorTopic3.asp>
you need to pass in the encoding e.g.
New XmlTextWriter("C:\inetpub\wwwroot\rss2\20061019\te st.xml",
System.Text.Encoding.UTF8)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 20 '06 #6
Hello,

Using code below to create an xml file, how do I specifiy utf-8 encoding in
the root element, ie create "<?xml version="1.0" encoding="utf-8"?>

Thanks!

-------------------------------------------

Dim xmlWriter As New
XmlTextWriter("C:\inetpub\wwwroot\rss2\20061019\te st.xml", Nothing)
xmlWriter.Formatting = Formatting.Indented

With xmlWriter
.WriteStartDocument()
.WriteStartElement("rss")
.WriteAttributeString("version", "2.0")
.WriteStartElement("channel")
.WriteElementString("title", "caseNumber" & ": " & "caseName")
.WriteElementString("link", "link")
.WriteElementString("description", "caseName")
.WriteElementString("lastBuildDate", Now.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") '<<<<<<<<<<<<<<<<<<<<<<<<<<<
'.WriteElementString("pubDate", caseAdded.ToString("ddd, dd MMM
yyyy hh:mm:ss") & " GMT") 'Now())
.WriteStartElement("item")
.WriteElementString("title", "description")
.WriteStartElement("guid")
.WriteAttributeString("isPermaLink", Nothing, "false")
.WriteString(Guid.NewGuid.ToString)
.WriteEndElement()
' .WriteElementString("title", description)
.WriteElementString("description", "caseNumber")
.WriteElementString("link", "link")
'.WriteElementString("pubDate", dateModified & " 12:00:00 GMT")
'Now().ToString) <---------------------------change
.WriteElementString("pubDate", Now().ToString("ddd, dd MMM yyyy
hh:mm:ss") & " GMT")
.WriteEndElement() '<<<<<<<<<<<<<<<<<<<<<
.WriteEndElement()
.WriteEndElement()
.WriteEndDocument()
.Flush()
.Close()
End With
xmlWriter = Nothing

you can also check this:

xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");

In that case there is no need to use
xmlWriter.WriteStartDocument()


Posted from http://www.topxml.com/renntp using reNNTP: the website based NNTP reader.
Nov 3 '06 #7
you can also check this:

xmlWriter.WriteProcessingInstruction("xml", "version='1.0'
encoding='UTF-8'");

In that case there is no need to use
xmlWriter.WriteStartDocument()
May be this is helpful to u.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community
Nov 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Amittai Aviram | last post by:
This XHTML 1.0 Strict page -- http://www.studiolirico.org/docs/settimana2003.html has a bilingual title in Italian and English. The principle language of the page is Italian, so the <html> tag...
4
by: Pascal.Schicht | last post by:
Hi! in my Application i have the need to get an XML Declaration without the Encoding Tag. Actual i get this declaration: <?xml version="1.0" encoding="utf-8"?> I need this: <?xml...
2
by: jmhmaine | last post by:
During the course of development cycle I receive HTML files from designers that use Macs and PCs, but use tools other then Visual Studio. So these files sometimes are not UTF-8 Encoded. I see...
4
by: Mark | last post by:
Hi... Just noticed something odd... In old ASP if you had query parameters that were invalid for their encoding (broken utf-8, say), ASP would give you back chars representing the 8-bit byte...
0
by: Chris McDonough | last post by:
ElementTree's XML serialization routine implied by tree._write(file, node, encoding, namespaces looks like this (elided): def _write(self, file, node, encoding, namespaces): # write XML to file...
4
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
3
by: Neil Cerutti | last post by:
How do I cope with faulty encoding settings? I'm writing an application that needs all internal character data to be stored in iso-8859-1. It also must allow input and output using stdin and...
0
by: UIVE | last post by:
Hey there. I have an .aspx page, where i have a pretty simple form on it. 2 text input fields and a submit button. The action of the page is then submitted to a different site which then handles...
6
by: hotani | last post by:
I am attempting to pull info from an LDAP server (Active Directory), but cannot specify an OU. In other words, I need to search users in all OU's, not a specific one. Here is what works: con...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.