XML 메시지를 보내는 타사 응용 프로그램과 통합하려고합니다.XML이 DocType 태그에서 탈 직렬화하지 못했습니다.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE theirObj SYSTEM "theirDTD-2.0.dtd">
<theirObj>
<properties>
<datasource>ThirdParty</datasource>
<datetime>2009-03-05T14:45:39</datetime>
</properties>
<data>
...
</data>
</theirObj>
내가 XmlSerializer를을 사용하여 직렬화하기 위해 노력하고있어 :
public theirObj Deserialize(string message) {
if(string.IsNullOrWhiteSpace(message)) {
throw new ArgumentNullException("message");
}
XmlSerializer xmlSerializer = new XmlSerializer(typeof(theirObj));
TextReader textReader = new StringReader(message);
using (XmlReader xmlReader = new XmlTextReader(textReader)) {
object deserializedObject = xmlSerializer.Deserialize(xmlReader);
theirObj ent = deserializedObject as theirObj ;
if (ent == null) {
throw new InvalidCastException("Unable to cast deserialized object to an theirObj object. {0}".FormatInvariant(deserializedObject));
}
return ent;
}
}
}
내가 xsd.exe를 사용하여 객체를 생성 그들의 XML은 다음과 같이 보인다.
<!DOCTYPE>
태그를 제거하면 정상적으로 비 직렬화됩니다.
XmlSerializer에서 <!DOCTYPE>
태그를 무시하는 방법이 있습니까?
XmlSerializer를 전달하기 전에 제거 할 수 있지만 XML 조작 수준으로 이동하지 않아도됩니다.
이동이 링크를 확인 얻을, 그것은 나를 위해 작동합니다. [솔루션] (http://stackoverflow.com/questions/26228371/allow-net-webapi-to-disregard-doctype-declaration) –