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\test.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



0
JohnHopper (10)
10/19/2006 5:15:03 PM
dotnet.xml 7266 articles. 0 followers. Follow

7 Replies
369 Views

Similar Articles

[PageSpeed] 0

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

0
anedza (69)
10/19/2006 6:34:02 PM
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\test.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
> 
> 
> 
0
JohnHopper (10)
10/19/2006 7:21:01 PM
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\test.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
> 
> 
> 
0
JohnHopper (10)
10/19/2006 7:34:01 PM
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

0
anedza (69)
10/20/2006 1:58:33 PM
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\test.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\test.xml", 
System.Text.Encoding.UTF8)



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
10/20/2006 2:06:35 PM
> 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\test.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.
0
rp.rohit (1)
11/3/2006 9:56:44 PM
you can also check this

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

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

May be this is helpful to u

---------------------------------
http://community.ihostasp.ne
ASP.NET Developer Community
0
11/3/2006 11:30:52 PM
Reply:

Similar Artilces:

Integration for SOP does not pick up credit card specified in source field
Version 8 Integration for SOP does not pick up the credit card specified in the source field it uses the default credit card against the debtor. Can someone let me know if there is a fix for this issue or if this is something that needs fixing in integration manager. kind regards Jen I have an integration in version 8 that pulls in credit card information and I have not seen this behavior. Do you have the original version of IM 8.0 or do you have any service packs installed? "Jen" wrote: > Version 8 Integration for SOP does not pick up the credit card specified in >...

How to specify UNSIGNED Byte in MS Access?
Hi. I have a MATLAB program that interacts with an MS Access database via MATLAB's "fastinsert" command. In one table, I'm inserting RGB pixel values, so it seemed natural that I'd use the "Byte" field size; however I eventually ran into a problem: I'm not allowed to insert values higher than 127 into the Byte columns! This would make sense if I had specified a signed-byte, but is there even such a thing? The Access documentation states that "Byte" can handle values from 0-255, and I haven't found anything else to explain this. A simple wa...

The specified date is invalid
Hello, We have specified the date settings for our CRM 3.0 (Rollup 2) installation as dd-mm-yyyy. When I'm adding a date, like 31/12/07 I get a warning: The specified date is invalid. Enter a date in the format: DD/MM/YYYY. When I enter a date like 31-12-07 I get no warning (and that's OK). Does anyone know were to change the date warning, so I can replace the / by - ? I didn't found it at the Messages section of the Contact entity. The system settings are set to dd-mm-yyyy. Thanks in advantage. LCOW- You can adjust the display of the date by going to ... Settings >...

Getting cursor to go to specified cell on opening
I want users when opening a location to open with the cursor at a specific spot rather than the last place I saved. Any ideas how? -- lewisjohn78 ------------------------------------------------------------------------ lewisjohn78's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30444 View this thread: http://www.excelforum.com/showthread.php?threadid=501047 Put something like this into a General module: Option Explicit sub auto_open() application.goto thisworkbook.worksheets("Sheet99").range("a99"),scroll:=true end sub Change the work...

Search not confined to specified discussion group
I believe there has been a change in how searches work on this discussion group. When I do a search, it no longer is confined to the discussion area specified Search for xxxx In: yyyyy but searches all discussion groups. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message...

making only specified columns visible
I am trying to create a macro that will allow the user of a spreadsheet to only view specified columns. It is easier to describe using an example: 1/05 1/05 2/05 2/05 3/05 matt 2 4 6 5 3 chris 3 4 2 7 1 sara 1 1 9 8 5 ann 5 4 3 3 6 If the user only wants to see data for the month of Feb., is there a way to have a macro hide all columns except those with a column heading of 2/05? Thank you for your help in advance. The following code goes in the sheet module. It assumes the column headings ar...

How to specify a fixed cell in a formula
Perhaps I am explaining myself in the wrong termonology but when I drag a cell into multiple cells below it the formula changes cells. How do I make it from changing cells. -- Dave Dave, you need to use a absolute, or mixed reference, form excel help Switch between relative, absolute, and mixed references Select the cell that contains the formula. In the formula bar , select the reference you want to change. Press F4 to toggle through the combinations. The "Changes To" column reflects how a reference type updates if a formula containing the reference is copied two cells down an...

The system file cannot be specified
I don't know if this is the right group but I hope someone can help. I have XP Home with Service Pack 3. I have a file on my NTFS slave drive with following entry in one of its directories: 01 - O 'twas a joyful sound to hear (Colchester) _Tansus/mq3 Obviously there's an invalid character in the name but I can't delete it. Every time I do, it says: "The system file cannot be specified." It has a file length of 0 bytes. I have tried many ways to delete this, but nothing works. Here are just two of the many things I've tried: http://support.mic...

Specifying chart graph
How can I specify on the same chart which fields I want to be displayed as Column and which fields I want to be displayed as Line? I have over seven fields. Let's say I want columns B through E to be columns and the other columns to be lines. Thanks in advance. Forget about the built-in custom types. Make a column chart. Then select a series you want to change to a line, choose Chart Type from the Chart menu, and choose a line style. Select another you want to change and press the F4 function key, and repeat as required. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials a...

Specifying the Default Namespace
Hi all, I have a pretty basic question... I have a method (below) which uses ExecuteXMLReader to load the output from a FOR XML Explicit stored procedure into an XML document, and then save the document to a file. It works well. Now, I am trying to add namespace support, and want my namespace to be something like "http://MapTo837P". How do I get this incorporated into the XML document? Thanks. With sqlCmdSendClaims .Parameters("@NPID").Value = NPIDCursor Dim doc As New XmlDocument cnSA.Open() Dim myXmlReader As XmlTextReader = .Ex...

Checking for existence of an attribute
What's the proper technique for checking for the existence of an attribute within a node? Lets say I did a SelectSingleNode which returned this element: <AnAddress city="San Francisco" state="CA" /> What's the best why of determining if the attribute zipcode exists in this node? If I try accessing the attribute with code like: ZipCode = myNode.Attributes("zipcode").Value I'll get an run-time error if the attribute doesn't exists. I know that I can try accessing the attribute within a try-catch block and catch the exceptio...

Getting Attribute value by using name
I am getting the element node list, and if any attributes are there, I am getting the attributes values by using the index eg 0- first element 1- second element aNode.Attributes.Item(1).InnerText But for some reason the order of the attributes is swapped , so my question is , how to get the attribute value using a name instead of the index values. I am new to xml and thanks for any help. eg . addressNodeList = xmlDoc.DocumentElement.GetElementsByTagName("UEP_STG_ADDRESS"); Console.WriteLine("Count=" + addressNodeList.Count); foreach (XmlNode aNode in addressNodeLi...

Specifying a cost based on price ranges
I have a schedule of rates which are fixed for a number of sites and whether the sites are local or further afield. For example Rate for 1-4 sites (local) �500 Rate for 1-4 sites(Distance) �600 Rate for 5-8 sites (local) �900 Rate for 5-8 sites(Distance) �1000 Rate for 9-12 sites (local) �1300 Rate for 9-12 sites(Distance) �1400 Rate for >12 sites (local) �1600 Rate for >12 sites(Distance) �1700 I have a spreadsheet which has each site as a separate row and I want to calculate a cost for each site depending on whether it is part of a group of say 4 or 8 etc. ...

Tab into specified cells
I'm looking to set up a worksheet so that when I open it up I can only tab into specific cells. Is there anyway of doing this? Thanks There are a few way. One is to unlock the cells you want to tab into (Format>Cells>Protection), and then lock the sheet (Tools>Protection>Protect Sheet) -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "sho" <anonymous@discussions.microsoft.com> wrote in message news:644601c47543$7c069000$a401280a@phx.gbl... > I'm looking to set ...

'CTest101Doc' : missing storage-class or type specifiers
Could someone please tell me what might be causing my problem below? I've been through this before but can't remember the solution. c:\hand in hand\test101\test101view.h(39) : error C2143: syntax error : missing ';' before '*' c:\hand in hand\test101\test101view.h(39) : error C2501: 'CTest101Doc' : missing storage-class or type specifiers c:\hand in hand\test101\test101view.h(39) : error C2501: 'GetDocument' : missing storage-class or type specifiers class CTest101View : public CView { protected: // create from serialization only CTest101View(); ...

Specifying end of day as a time value
I would like to be able to ented a date/time value into a cell, that specifies the 24 hour value. I have tried using something like, 11/3/2003 23:59:59.99, and tried rounding up, but so far no success. I would like to be able to use this value with the value in a previous cell and simply derive the difference. I'm just having trouble specifying this value. So, what do I enter to cause Excel to see the value as specifiing the end of that day. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from ht...

specify return
Simple question but I'm getting fustrated. I just want to open a query that shows only records for value entered into text box. Could someone show me what to add to this code to make it specify only the records for value entered into txtName. Private Sub cmdView_Click() Dim stLinkCriteria As String If IsNull(Me.txtName) Then stLinkCriteria = stLinkCriteria & " and [Name]=" & "'" & Me.txtName & "'" End If DoCmd.OpenQuery "q_NameQuery" End Sub On Fri, 22 Jun 2007 13:06:01 -0700, Dan @BCBS wrote: > Simple questio...

List records that do not include specified value
I have a very basic select query that list all the records from a table SELECT tbl_cngu.cngu_no, tbl_cngu_recalls.recall_no FROM tbl_cngu LEFT JOIN tbl_cngu_recalls ON tbl_cngu.cngu_no = tbl_cngu_recalls.cngu_no ORDER BY tbl_cngu.cngu_no, tbl_cngu_recalls.recall_no DESC; Now I need to apply a twist and do no know how. The [recall_no] field is a numeric field 1,2,3,4,5,... and what I would like to do is supply the query with a [recall_no] value and have the query return those records for which there is no such [recall_no] for a each given [cngu_no]. How would I do this? T...

Store information in Custom Attribute
Dear All, I have a custom attribute added to User OU, I want to store multiple information in this attribute like in an table: Application Name1 , User Name1, Password1 Application Name2 , User Name2, Password2 etc... There could be many application with different user names and password for any given user. what would you recommend? Thanks, Suresh -- sureshpalani ------------------------------------------------------------------------ sureshpalani's Profile: http://forums.techarena.in/members/162371.htm View this thread: http://forums.techarena.in/active-d...

Rules- through specified account / to specified folder not working
I am using Windows7 and Outlook 2007 with two separate email accounts. I am having trouble setting up the email rules to move emails that come in through my account into my folder. I go to the rules wizard and select "New Rule". I check the "Start From a Blank Rule", "Check Messages When They Arrive", "through the specified account" and select my account. I hit next and select "move to the specified folder" and select my folder in Personal Folders. I hit "Finish" to exit the wizard and go back to the Rules and Alerts wind...

No CRM user exists with specified domain name and user id (CRM 4.0
I am getting the above message when i attempt to connect to my CRM server from a users PC. The Outlook client was installed, he got into CRM fine one day then the next day he went to expand the folder in Outlook for CRM and was prompted for a user name and password to access the server. He entered the administrator account and was denied access. Ever since i cannot get into CRM from his PC as him. I can logon fine as him via the web version from another PC but cannot get into either the web version or outlook client version from his PC. I have removed CRM for Outlook, got rid of r...

Cannot Find Specified Path
Hello: I'm using Office XP, and I'm getting an intermittent error message when I try to send messages using Outlook. I am connected to an Exchange Server in my office building. Every 3rd or 4th message I try to send, I get the following error message: Outlook error - Cannot find the specified path. I get the same message if I try to send or save the e- mail. To get around it, I open a new message and copy everything over from the message that won't send. The new message I just opened always works perfectly. It doesn't seem to matter whether I am opening a new ...

Getting attribute value from xml using xpath to get file path
I have the following xml file: <?xml version="1.0" encoding="utf-8" ?> <course id="2555" title="Developing Microsoft .NET Applications for Windows (Visual C# .NET)" length="5 days" source="http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx"> <module id="1" title="Introducing Windows Forms" location="D:\Disk-C\Documents and Settings\orit_itzhar.ATRICA\My Documents\XML\csharp"> <lesson id="1.1"> <subject>Creating a Form</subject> <f...

Can not delete from specified Tables
Below is my SQL Code - Confirmation Entries such that if PalmHeight1 = PalmHeight2 then Delete that entry in the second table. DELETE PalmHeight.Height, PalmHeightSecond.*, PalmHeight.RDate FROM PalmHeight INNER JOIN PalmHeightSecond ON (PalmHeight.Palm = PalmHeightSecond.Palm) AND (PalmHeight.Plot = PalmHeightSecond.Plot) AND (PalmHeight.Trial = PalmHeightSecond.Trial) WHERE (((PalmHeight.Height)=[PalmHeightSecond].[Height]) AND ((PalmHeight.RDate)=[PalmHeightSecond].[RDate])); Am not able to delete. Trial, Palm, Plot and Date is related. Is this where the problem is? Such that there are ...

Specifying a Range.
Please bear with me. This is probably a painfully fundamental question. I need to specify a range of 48 cells in a sum formula. For example, =SUM(A10:A57). Is there another way to achieve the same results by subtraction? Something like, =SUM(The cell I want to end with - the quantity of cells)? Hopefully, the question makes sense. Any help would be greatly appreciated. Perhaps you mean something like this....... =G1-SUM(A10-A57) Vaya con Dios, Chuck, CABGx3 "Jocco" <Jocco@discussions.microsoft.com> wrote in message news:E07694E2-7F9C-4808-8E49-1319784B824E@microsoft....