1
다음 XML을 감안할 때
이있는 경우 XML을 역 직렬화하는 방법 :중첩 된 객체가 namesapce
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<title>Title One</title>
</webPart>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<title>Title Two</title>
</webPart>
</webParts>
그리고 다음 C# : 나는 XML을 역 직렬화하기 위해 노력하고있어
[XmlRoot("webParts")]
public class webParts : List<webPart>
{
static public webParts FromXml(string path)
{
webParts returnValue = null;
var serializer = new XmlSerializer(typeof(webParts));
using (var stream = File.OpenRead(path))
{
returnValue = (webParts)serializer.Deserialize(stream);
}
return returnValue;
}
}
public class webPart
{
public string title { get; set; }
}
합니다. XML에 대한 제어권이 없기 때문에 C#을 변경할 수 있습니다. deserialization 중에 webPart 요소에서 네임 스페이스를 제거하면이 작업을 수행 할 수 있습니다. 그러나, 일종의 kludgy 보인다. XML 속성이 클래스에 추가되어야한다고 생각하지만 Namespace 태그의 올바른 조합을 찾을 수 없습니다. 위 코드는 webParts를 deserialize하지만 아직 0인데 webPart 요소 중 어느 것도 deserialize되지 않습니다. 이 작업을하기 위해 C#에서 수행해야하는 작업은 무엇입니까? 감사!
그 해답이 눈물을 흘 렸습니다. Rufo 선생님, 고마워요! 그것이 VS에 있다는 것을 결코 알지 못했다. – tallman