사용자 지정 오류 메시지를 제공하거나 적어도 내 웹 API에 대한 XML 게시물의 요소 이름을 지정하는 방법을 알아 내려고합니다. 현재 내가 받고있는 모델 상태 오류는
XML 문서 (2, 4)에 오류가 있습니다.
이 오류의 내부 예외는 다음과 같은 추가 정보를 제공합니다.
'false fds'문자열은 유효한 부울 값이 아닙니다.
유효하지 않은 값을 포함하는 요소를 나타내는 사용자에게 더 구체적인 내용을 반환하고, 해당 값이 존재하는 위치를 확인하기 위해 XML을 검색하도록하고 싶습니다.
내가 게시하는 XML은 다음과 같습니다.
<?xml version='1.0'?>
<checkin>
<checkinType>1</checkinType>
<server>server1</server>
<notes>New Checkin</notes>
<productCheckins>
<ihsCheckin>
<vendor>IBM</vendor>
<make>HTTP Server</make>
<model></model>
<version>8.5.5.0</version>
<installLocation>/opt/IBM</installLocation>
<is64Bit>false fds</is64Bit>
</ihsCheckin>
</productCheckins>
</checkin>
다음은 변환하려는 클래스입니다.
[XmlRoot("checkin")]
public class Checkin
{
[XmlElement("checkinTime")]
public DateTime CheckinTime { get; set; }
[XmlElement("checkType")]
public int CheckinType { get; set; }
[XmlElement("notes")]
public string Notes { get; set; }
[XmlElement("server")]
public string Server { get; set; }
[XmlArray("productCheckins")]
[XmlArrayItem("wasCheckin", typeof(WASCheckin))]
[XmlArrayItem("ihsCheckin", typeof(IHSCheckin))]
public List<ProductCheckin> ProductCheckins { get; set; }
}
public class ProductCheckin
{
[XmlElement("vendor")]
public string Vendor { get; set; }
[XmlElement("make")]
public string Make { get; set; }
[XmlElement("model")]
public string Model { get; set; }
[XmlElement("version")]
public string Version { get; set; }
[XmlElement("installLocation")]
public string InstallLocation { get; set; }
[XmlElement("is64Bit")]
public bool Is64Bit { get; set; }
}
기본적으로 오류는 is64Bit 요소와 관련이 있지만 XML을 수동으로 구문 분석하는 방법은 아직 보지 못했습니다.
나는 그것에 동의해야한다 :
<is64Bit>false fds</is64Bit>
다음에 대해 유효한 값이 아닙니다.
[XmlElement("is64Bit")]
public bool Is64Bit { get; set; }
다음과 같이 취급 할 수 있습니다 string
.
[XmlElement("is64Bit")]
public string Is64Bit { get; set; }
나중에 별도로 처리하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다