dotnet xml:
In my .net ,i need to generate an xml file , however, user may input a chinese character, Then , the xml will got something unknow characters. the following is my code, Does anyone know how to solve it ?? Private Sub Init() With AMSXML ..Formatting = Formatting.Indented ..Indentation = 4 ..IndentChar = " " ..WriteStartDocument() ..WriteDocType("SOGenericInterchange", Nothing, "SOGenericInterchange.dtd", Nothing) ..WriteStartElement("SOGenericInterchange") End With End Sub Private Sub InterchangeHeaderIdentification() Try With AMSXML ..WriteStartElement("InterchangeHeaderIdentification") ..WriteElementString("senderID", strSenderid) ..WriteElementString("interchangeControlReference", strFilename) ..WriteElementString("recipientID", strReceiveId) <--- problem here . ..WriteElementString("payerID", "") ..WriteEndElement() ..............................
In order to store non-ANSI characters in xml file, you need to define encoding. This first line of your xml file should be: <?xml version="1.0" encoding="utf-8" ?> or other encoding matches your language. [quoted text, click to view] "Agnes" <agnes@dynamictech.com.hk> wrote in message news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... > In my .net ,i need to generate an xml file , however, user may input a > chinese character, Then , the xml will got something unknow characters. > the > following is my code, Does anyone know how to solve it ?? > > Private Sub Init() > With AMSXML > .Formatting = Formatting.Indented > .Indentation = 4 > .IndentChar = " " > .WriteStartDocument() > .WriteDocType("SOGenericInterchange", Nothing, "SOGenericInterchange.dtd", > Nothing) > .WriteStartElement("SOGenericInterchange") > End With > > End Sub > Private Sub InterchangeHeaderIdentification() > Try > With AMSXML > .WriteStartElement("InterchangeHeaderIdentification") > .WriteElementString("senderID", strSenderid) > .WriteElementString("interchangeControlReference", strFilename) > .WriteElementString("recipientID", strReceiveId) <--- problem here . > .WriteElementString("payerID", "") > .WriteEndElement() > ............................. > >
thanks, my XML already got it , but still cannot output chinese character.. "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:uUpGb7SfFHA.1444@TK2MSFTNGP10.phx.gbl... [quoted text, click to view] > In order to store non-ANSI characters in xml file, you need to define > encoding. > This first line of your xml file should be: > <?xml version="1.0" encoding="utf-8" ?> > or other encoding matches your language. > > "Agnes" <agnes@dynamictech.com.hk> wrote in message > news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... >> In my .net ,i need to generate an xml file , however, user may input a >> chinese character, Then , the xml will got something unknow characters. >> the >> following is my code, Does anyone know how to solve it ?? >> >> Private Sub Init() >> With AMSXML >> .Formatting = Formatting.Indented >> .Indentation = 4 >> .IndentChar = " " >> .WriteStartDocument() >> .WriteDocType("SOGenericInterchange", Nothing, >> "SOGenericInterchange.dtd", >> Nothing) >> .WriteStartElement("SOGenericInterchange") >> End With >> >> End Sub >> Private Sub InterchangeHeaderIdentification() >> Try >> With AMSXML >> .WriteStartElement("InterchangeHeaderIdentification") >> .WriteElementString("senderID", strSenderid) >> .WriteElementString("interchangeControlReference", strFilename) >> .WriteElementString("recipientID", strReceiveId) <--- problem here . >> .WriteElementString("payerID", "") >> .WriteEndElement() >> ............................. >> >> > >
How big is your xml file? Can you attach it here? [quoted text, click to view] "Agnes" <agnes@dynamictech.com.hk> wrote in message news:O54fhAWfFHA.3612@TK2MSFTNGP12.phx.gbl... > Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) <-- Already > Exist > > IF i set breakpoint, I can see my chinese character in watch window. > However, if i use IE or notepad to read it. > The chinese character still cannot show. > "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:ui4rwGUfFHA.2156@TK2MSFTNGP14.phx.gbl... >> Agnes, >> >> Can you put a breakpoint to see what is in strReceiveId variable? >> >> I made a small application to test, it can write and read Chinese or >> other characters OK: >> Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) >> >> writer.WriteStartDocument() >> >> writer.WriteStartElement("node1") >> >> writer.WriteElementString("English", TextBox1.Text) >> >> writer.WriteElementString("Chinese", TextBox2.Text) >> >> writer.WriteEndElement() >> >> writer.WriteEndDocument() >> >> writer.Flush() >> >> writer.Close() >> >> >> >> >> >> >> >> >> >> "Agnes" <agnes@dynamictech.com.hk> wrote in message >> news:O915RXTfFHA.1304@TK2MSFTNGP10.phx.gbl... >>> thanks, my XML already got it , but still cannot output chinese >>> character.. >>> "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> >>> glsD:uUpGb7SfFHA.1444@TK2MSFTNGP10.phx.gbl... >>>> In order to store non-ANSI characters in xml file, you need to define >>>> encoding. >>>> This first line of your xml file should be: >>>> <?xml version="1.0" encoding="utf-8" ?> >>>> or other encoding matches your language. >>>> >>>> "Agnes" <agnes@dynamictech.com.hk> wrote in message >>>> news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... >>>>> In my .net ,i need to generate an xml file , however, user may input a >>>>> chinese character, Then , the xml will got something unknow >>>>> characters. the >>>>> following is my code, Does anyone know how to solve it ?? >>>>> >>>>> Private Sub Init() >>>>> With AMSXML >>>>> .Formatting = Formatting.Indented >>>>> .Indentation = 4 >>>>> .IndentChar = " " >>>>> .WriteStartDocument() >>>>> .WriteDocType("SOGenericInterchange", Nothing, >>>>> "SOGenericInterchange.dtd", >>>>> Nothing) >>>>> .WriteStartElement("SOGenericInterchange") >>>>> End With >>>>> >>>>> End Sub >>>>> Private Sub InterchangeHeaderIdentification() >>>>> Try >>>>> With AMSXML >>>>> .WriteStartElement("InterchangeHeaderIdentification") >>>>> .WriteElementString("senderID", strSenderid) >>>>> .WriteElementString("interchangeControlReference", strFilename) >>>>> .WriteElementString("recipientID", strReceiveId) <--- problem here . >>>>> .WriteElementString("payerID", "") >>>>> .WriteEndElement() >>>>> ............................. >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >
Agnes, Can you put a breakpoint to see what is in strReceiveId variable? I made a small application to test, it can write and read Chinese or other characters OK: Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) writer.WriteStartDocument() writer.WriteStartElement("node1") writer.WriteElementString("English", TextBox1.Text) writer.WriteElementString("Chinese", TextBox2.Text) writer.WriteEndElement() writer.WriteEndDocument() writer.Flush() writer.Close() [quoted text, click to view] "Agnes" <agnes@dynamictech.com.hk> wrote in message news:O915RXTfFHA.1304@TK2MSFTNGP10.phx.gbl... > thanks, my XML already got it , but still cannot output chinese > character.. > "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> > glsD:uUpGb7SfFHA.1444@TK2MSFTNGP10.phx.gbl... >> In order to store non-ANSI characters in xml file, you need to define >> encoding. >> This first line of your xml file should be: >> <?xml version="1.0" encoding="utf-8" ?> >> or other encoding matches your language. >> >> "Agnes" <agnes@dynamictech.com.hk> wrote in message >> news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... >>> In my .net ,i need to generate an xml file , however, user may input a >>> chinese character, Then , the xml will got something unknow characters. >>> the >>> following is my code, Does anyone know how to solve it ?? >>> >>> Private Sub Init() >>> With AMSXML >>> .Formatting = Formatting.Indented >>> .Indentation = 4 >>> .IndentChar = " " >>> .WriteStartDocument() >>> .WriteDocType("SOGenericInterchange", Nothing, >>> "SOGenericInterchange.dtd", >>> Nothing) >>> .WriteStartElement("SOGenericInterchange") >>> End With >>> >>> End Sub >>> Private Sub InterchangeHeaderIdentification() >>> Try >>> With AMSXML >>> .WriteStartElement("InterchangeHeaderIdentification") >>> .WriteElementString("senderID", strSenderid) >>> .WriteElementString("interchangeControlReference", strFilename) >>> .WriteElementString("recipientID", strReceiveId) <--- problem here . >>> .WriteElementString("payerID", "") >>> .WriteEndElement() >>> ............................. >>> >>> >> >> > >
Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) <-- Already Exist IF i set breakpoint, I can see my chinese character in watch window. However, if i use IE or notepad to read it. The chinese character still cannot show. "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D:ui4rwGUfFHA.2156@TK2MSFTNGP14.phx.gbl... [quoted text, click to view] > Agnes, > > Can you put a breakpoint to see what is in strReceiveId variable? > > I made a small application to test, it can write and read Chinese or other > characters OK: > Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) > > writer.WriteStartDocument() > > writer.WriteStartElement("node1") > > writer.WriteElementString("English", TextBox1.Text) > > writer.WriteElementString("Chinese", TextBox2.Text) > > writer.WriteEndElement() > > writer.WriteEndDocument() > > writer.Flush() > > writer.Close() > > > > > > > > > > "Agnes" <agnes@dynamictech.com.hk> wrote in message > news:O915RXTfFHA.1304@TK2MSFTNGP10.phx.gbl... >> thanks, my XML already got it , but still cannot output chinese >> character.. >> "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> >> glsD:uUpGb7SfFHA.1444@TK2MSFTNGP10.phx.gbl... >>> In order to store non-ANSI characters in xml file, you need to define >>> encoding. >>> This first line of your xml file should be: >>> <?xml version="1.0" encoding="utf-8" ?> >>> or other encoding matches your language. >>> >>> "Agnes" <agnes@dynamictech.com.hk> wrote in message >>> news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... >>>> In my .net ,i need to generate an xml file , however, user may input a >>>> chinese character, Then , the xml will got something unknow characters. >>>> the >>>> following is my code, Does anyone know how to solve it ?? >>>> >>>> Private Sub Init() >>>> With AMSXML >>>> .Formatting = Formatting.Indented >>>> .Indentation = 4 >>>> .IndentChar = " " >>>> .WriteStartDocument() >>>> .WriteDocType("SOGenericInterchange", Nothing, >>>> "SOGenericInterchange.dtd", >>>> Nothing) >>>> .WriteStartElement("SOGenericInterchange") >>>> End With >>>> >>>> End Sub >>>> Private Sub InterchangeHeaderIdentification() >>>> Try >>>> With AMSXML >>>> .WriteStartElement("InterchangeHeaderIdentification") >>>> .WriteElementString("senderID", strSenderid) >>>> .WriteElementString("interchangeControlReference", strFilename) >>>> .WriteElementString("recipientID", strReceiveId) <--- problem here . >>>> .WriteElementString("payerID", "") >>>> .WriteEndElement() >>>> ............................. >>>> >>>> >>> >>> >> >> > >
Please show how you are constructing the AMSXML writer. It should be something like this: new System.Xml.XmlTextWriter(filename, System.Text.Encoding.UTF8) [quoted text, click to view] "Agnes" <agnes@dynamictech.com.hk> wrote in message news:O915RXTfFHA.1304@TK2MSFTNGP10.phx.gbl... > thanks, my XML already got it , but still cannot output chinese > character.. > "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> > ¼¶¼g©ó¶l¥ó·s»D:uUpGb7SfFHA.1444@TK2MSFTNGP10.phx.gbl... >> In order to store non-ANSI characters in xml file, you need to define >> encoding. >> This first line of your xml file should be: >> <?xml version="1.0" encoding="utf-8" ?> >> or other encoding matches your language. >> >> "Agnes" <agnes@dynamictech.com.hk> wrote in message >> news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... >>> In my .net ,i need to generate an xml file , however, user may input a >>> chinese character, Then , the xml will got something unknow characters. >>> the >>> following is my code, Does anyone know how to solve it ?? >>> >>> Private Sub Init() >>> With AMSXML >>> .Formatting = Formatting.Indented >>> .Indentation = 4 >>> .IndentChar = " " >>> .WriteStartDocument() >>> .WriteDocType("SOGenericInterchange", Nothing, >>> "SOGenericInterchange.dtd", >>> Nothing) >>> .WriteStartElement("SOGenericInterchange") >>> End With >>> >>> End Sub >>> Private Sub InterchangeHeaderIdentification() >>> Try >>> With AMSXML >>> .WriteStartElement("InterchangeHeaderIdentification") >>> .WriteElementString("senderID", strSenderid) >>> .WriteElementString("interchangeControlReference", strFilename) >>> .WriteElementString("recipientID", strReceiveId) <--- problem here . >>> .WriteElementString("payerID", "") >>> .WriteEndElement() >>> ............................. >>> >>> >> >> > >
[quoted text, click to view] Agnes wrote: > Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) <-- > Already Exist > > IF i set breakpoint, I can see my chinese character in watch window. > However, if i use IE or notepad to read it. The chinese character > still cannot show. "Wencheng Magiya"
Try this: Repeat your test using IE and set View->Encoding->Unicode (UTF-8). Are the characters displayed now? Cheers, -- http://www.joergjooss.de
Then you are doing everything correctly. The strange characters you are seeing in the file are probably the UTF-8 encoding of those chinese characters, which is perfectly fine. Whoever is viewing the file must do a corresponding UTF-8 decode. See http://msdn.microsoft.com/library/en-us/dnxml/html/xmlencodings.asp. [quoted text, click to view] "Agnes" <agnes@dynamictech.com.hk> wrote in message news:O54fhAWfFHA.3612@TK2MSFTNGP12.phx.gbl... > Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) <-- Already > Exist > > IF i set breakpoint, I can see my chinese character in watch window. > However, if i use IE or notepad to read it. > The chinese character still cannot show. > "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> > ¼¶¼g©ó¶l¥ó·s»D:ui4rwGUfFHA.2156@TK2MSFTNGP14.phx.gbl... >> Agnes, >> >> Can you put a breakpoint to see what is in strReceiveId variable? >> >> I made a small application to test, it can write and read Chinese or >> other characters OK: >> Dim writer As New Xml.XmlTextWriter("test.xml", Encoding.UTF8) >> >> writer.WriteStartDocument() >> >> writer.WriteStartElement("node1") >> >> writer.WriteElementString("English", TextBox1.Text) >> >> writer.WriteElementString("Chinese", TextBox2.Text) >> >> writer.WriteEndElement() >> >> writer.WriteEndDocument() >> >> writer.Flush() >> >> writer.Close() >> >> >> >> >> >> >> >> >> >> "Agnes" <agnes@dynamictech.com.hk> wrote in message >> news:O915RXTfFHA.1304@TK2MSFTNGP10.phx.gbl... >>> thanks, my XML already got it , but still cannot output chinese >>> character.. >>> "Wencheng Magiya" <gold1laser1remove1s@hotmail.com> >>> glsD:uUpGb7SfFHA.1444@TK2MSFTNGP10.phx.gbl... >>>> In order to store non-ANSI characters in xml file, you need to define >>>> encoding. >>>> This first line of your xml file should be: >>>> <?xml version="1.0" encoding="utf-8" ?> >>>> or other encoding matches your language. >>>> >>>> "Agnes" <agnes@dynamictech.com.hk> wrote in message >>>> news:O1eaNDRfFHA.3304@TK2MSFTNGP12.phx.gbl... >>>>> In my .net ,i need to generate an xml file , however, user may input a >>>>> chinese character, Then , the xml will got something unknow >>>>> characters. the >>>>> following is my code, Does anyone know how to solve it ?? >>>>> >>>>> Private Sub Init() >>>>> With AMSXML >>>>> .Formatting = Formatting.Indented >>>>> .Indentation = 4 >>>>> .IndentChar = " " >>>>> .WriteStartDocument() >>>>> .WriteDocType("SOGenericInterchange", Nothing, >>>>> "SOGenericInterchange.dtd", >>>>> Nothing) >>>>> .WriteStartElement("SOGenericInterchange") >>>>> End With >>>>> >>>>> End Sub >>>>> Private Sub InterchangeHeaderIdentification() >>>>> Try >>>>> With AMSXML >>>>> .WriteStartElement("InterchangeHeaderIdentification") >>>>> .WriteElementString("senderID", strSenderid) >>>>> .WriteElementString("interchangeControlReference", strFilename) >>>>> .WriteElementString("recipientID", strReceiveId) <--- problem here . >>>>> .WriteElementString("payerID", "") >>>>> .WriteEndElement() >>>>> ............................. >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >
Don't see what you're looking for? Try a search.
|