0
<response id=\"f57127c5-c7c5-4e31-bf60-a4b47ddb95c6\">
   <error-code>0</error-code>
   <error-message></error-message>
   <result xsi:type=\"entityWrapper\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
        <elements>
            <element xsi:type=\"decisionImpl\">
                <cityId>0</cityId>
                <createdDate>2015-08-21T14:58:46.570+07:00</createdDate>    
                <createdUser>5</createdUser
                <effectiveDate>2015-07-05T17:03:44.947+07:00</effectiveDate>
                <enterpriseId>5</enterpriseId>
                <equipmentSystem>K</equipmentSystem>
                <id xsi:type=\"xs:long\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">8</id><invoiceType>1;</invoiceType>
                <modifiedDate>2015-08-21T14:58:47.045+07:00</modifiedDate>
                <modifiedUser>5</modifiedUser><number>HC889</number>
                <proponentName>Quang</proponentName>
                <status>0</status>
            </element>
        </elements>
    </result>
</response>

My Xml like that

public class Decision
    {
        [XmlAttribute(Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
        public String type = Constants.Type.DECISION;
        [XmlElement(ElementName = "id")]
        public long id { get; set; }
        [XmlElement(ElementName = "enterpriseId")]
        public long enterpriseId { get; set; }
        [XmlElement(ElementName = "number")]
        public String number { get; set; }
        [XmlElement(ElementName = "proponentName")]
        public String proponentName { get; set; }
        [XmlElement(ElementName = "equipmentSystem")]
        public String equipmentSystem { get; set; }
        [XmlElement(ElementName = "softwareApplication")]
        public String softwareApplication { get; set; }
        [XmlElement(ElementName = "processCreator")]
        public String processCreator { get; set; }
        [XmlElement(ElementName = "responsible")]
        public String responsible { get; set; }
        [XmlElement(ElementName = "effectiveDate")]
        public DateTime effectiveDate { get; set; }
        [XmlElement(ElementName = "cityId")]
        public long cityId { get; set; }
        [XmlElement(ElementName = "recipient")]
        public String recipient { get; set; }
        [XmlElement(ElementName = "invoiceType")]
        public String invoiceType { get; set; }
        [XmlElement(ElementName = "status")]
        public int status { get; set; }
        [XmlElement(ElementName = "createdDate")]
        public DateTime createdDate { get; set; }
        [XmlElement(ElementName = "modifiedDate")]
        public DateTime modifiedDate { get; set; }
        [XmlElement(ElementName = "createdUser")]
        public String createdUser { get; set; }
        [XmlElement(ElementName = "modifiedUser")]
        public String modifiedUser { get; set; }
    }

    [Serializable]
    [XmlRoot(ElementName = "response")]
    public class MessageResponseWrapperList<T>
    {
        [XmlAttribute(AttributeName = "id")]
        public String id { get; set; }
        [XmlElement(ElementName = "error-code")]
        public String errorCode { get; set; }
        [XmlElement(ElementName = "error-message")]
        public String errorMessage { get; set; }
        [XmlElement(ElementName = "result")]
        public DataWrapper<T> wrapper { get; set; }

    }

    [Serializable]
    public class DataWrapper<T>
    {
        [XmlAttribute(Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
        public String type = "entityWrapper";
        [XmlArray(ElementName = "elements")]
        [XmlArrayItem(ElementName = "element")]
        public List<T> result { get; set; }
    }

My function, I want to deserialize to MessageResponseWrapperList with List

public static MessageResponseWrapperList<T> fromXmlWrapper<T>(String xml)
        {
            StringReader reader = new StringReader(xml);
            XmlSerializer serializer = new XmlSerializer(typeof(MessageResponseWrapperList<T>));
            MessageResponseWrapperList<T> t = (MessageResponseWrapperList<T>)serializer.Deserialize(reader);
            return t;
        }

But I get error

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

Additional information: There is an error in XML document (1, 165).

2 Answers 2

3

It's true that there's an error in XML document

Change

<createdUser>5</createdUser

to

<createdUser>5</createdUser>

Close bracket.

Sign up to request clarification or add additional context in comments.

1 Comment

that's not true because xml not error like you said. I check again error again
1

A double quote doesn't need a backslash in an xml file. Below is your xml with all errors removed

<?xml version="1.0" encoding="utf-8" ?>
<response id="f57127c5-c7c5-4e31-bf60-a4b47ddb95c6">
  <error-code>0</error-code>
  <error-message></error-message>
  <result xsi:type="entityWrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <elements>
      <element xsi:type="decisionImpl">
        <cityId>0</cityId>
        <createdDate>2015-08-21T14:58:46.570+07:00</createdDate>
        <createdUser>5</createdUser>
        <effectiveDate>2015-07-05T17:03:44.947+07:00</effectiveDate>
        <enterpriseId>5</enterpriseId>
        <equipmentSystem>K</equipmentSystem>
        <id xsi:type="xs:long" xmlns:xs="http://www.w3.org/2001/XMLSchema">8</id>
        <invoiceType>1;</invoiceType>
        <modifiedDate>2015-08-21T14:58:47.045+07:00</modifiedDate>
        <modifiedUser>5</modifiedUser>
        <number>HC889</number>
        <proponentName>Quang</proponentName>
        <status>0</status>
      </element>
    </elements>
  </result>
</response>
​

6 Comments

i don't know what's you mean?
when you have as double quote inside a sting you need to use a backslash like "There is a double quote at end of tis string\"". Note the two double quotes at the end together. You do not need to do this in an XML document. So an attribute looks like this version="1.0", not version=\"1.0\".
oh no! that is escape space character in String not "double quote"
I know. There are a number of places in your original XML where it is obviously WRONG!!! Attributes should not have the escape character.
when i type String sample = "<id name=\"abc\">"; i need that! so you think wrong my way :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.