다음과 같은 수업이 있습니다.
[Serializable]
public class SomeModel
{
[XmlElement("CustomerName")]
public string CustomerName { get; set; }
[XmlElement("")]
public int CustomerAge { get; set; }
}
(일부 테스트 데이터로 채워진 경우) XmlSerializer.Serialize ()를 사용하여 직렬화되고 다음 XML이 생성됩니다.
<SomeModel>
<CustomerName>John</CustomerName>
<CustomerAge>55</CustomerAge>
</SomeModel>
내가 필요로하는 것은 :
<SomeModel>
<CustomerName>John</CustomerName>
55
</SomeModel>
두 번째 xml 요소의 경우 자체 태그가 없어야합니다. 이것이 가능할까요? 감사합니다.
장식 CustomerAge
과 XMLTEXT 대신 XmlElement
.
당신은 또한의 유형을 변경해야합니다 CustomerAge
에서 int
에 string
당신이 원하지 않을 경우이 같은 직렬화에 대한 추가 속성을 가지고해야합니다 :
public class SomeModel
{
[XmlElement("CustomerName")]
public string CustomerName { get; set; }
[XmlText]
public string CustomerAgeString { get { return CustomerAge.ToString(); } set { throw new NotSupportedException("Setting the CustomerAgeString property is not supported"); } }
[XmlIgnore]
public string CustomerAge { get; set; }
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다