[Mono-bugs] [Bug 676681] XML Serialization - unexpected characters and missing ending ">"

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Mar 7 00:13:49 EST 2011


https://bugzilla.novell.com/show_bug.cgi?id=676681

https://bugzilla.novell.com/show_bug.cgi?id=676681#c3


Atsushi Enomoto <aenomoto at novell.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #3 from Atsushi Enomoto <aenomoto at novell.com> 2011-03-07 05:13:48 UTC ---
NET perfectly gives the same output that includes UTF8 byte order mark as
mono:

$ ./676681.exe
?<?xml version="1.0" encoding="utf-8"?><AcdCpaInfo
xmlns:xsd="http://www.w3.org/
2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Applicati
onId>50</ApplicationId><IdCall>58682074963644</IdCall><Cpa>586820749</Cpa><SwdNo
tice>NB</SwdNotice><SudNotice>ZA</SudNotice><IdRequest>4097</IdRequest></AcdCpaI
nfo>

$ mono 676681.exe
?<?xml version="1.0" encoding="utf-8"?><AcdCpaInfo
xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Applicati
onId>50</ApplicationId><IdCall>58682074963644</IdCall><Cpa>586820749</Cpa><SwdNo
tice>NB</SwdNotice><SudNotice>ZA</SudNotice><IdRequest>4097</IdRequest></AcdCpaI
nfo>


Your code fragment is not complete, so I have created one that is fully
compiable:


using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

[Serializable]
    public class AcdCpaInfo 
    {      
        public UInt16 ApplicationId;
        public string IdCall;       
        public string Cpa;          
        public string SwdNotice;    
        public string SudNotice;    
        public UInt32 IdRequest;           
    }

public class Test
{
static object acdCpaInfo = new AcdCpaInfo
            {
                ApplicationId = 50,
                Cpa = "586820749",
                IdCall = "586820749" + 0xF89C,
                SudNotice = "ZA",
                SwdNotice = "NB",
                IdRequest = 0xFFF + 2
            };

    public static void Main ()
    {
        Console.WriteLine (GetXml ());
    }

    static string GetXml ()
    {
var memoryStream = new MemoryStream();           
            var xs = new XmlSerializer(acdCpaInfo.GetType ());
            var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
            xs.Serialize(xmlTextWriter, acdCpaInfo);
            memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
            var xmlizedString = Utf8ByteArrayToString(memoryStream.ToArray());
            return xmlizedString;
    }

    static String Utf8ByteArrayToString(Byte[] characters)
        {

            var encoding = new UTF8Encoding();
            var constructedString = encoding.GetString(characters);
            return (constructedString);
        }
}

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list