0
Visual Studio 2010 (C#)을 사용하고 XML 비 직렬화 코드에 몇 가지 문제가 있습니다. XML을 올바르게 읽을 수는 없습니다.역 직렬화 및 XML 문제
[Serializable()]
public class Command
{
[System.Xml.Serialization.XmlAttribute("cmd_id")]
public int cmd_id { get; set; }
[System.Xml.Serialization.XmlAttribute("state_id")]
public int state_id { get; set; }
[System.Xml.Serialization.XmlAttribute("label")]
public string label { get; set; }
[System.Xml.Serialization.XmlAttribute("cmd_type")]
public string cmd_type { get; set; }
[System.Xml.Serialization.XmlAttribute("cmd_string")]
public string cmd_string { get; set; }
}
[Serializable()]
[System.Xml.Serialization.XmlRoot("commands")]
public class CommandCollection
{
[XmlArray("commands")]
[XmlArrayItem("command", typeof(Command))]
public Command[] Command { get; set; }
}
public void XMLStrings(string myXML)
{
CommandCollection commandscollection = null;
XmlSerializer dserial = new XmlSerializer(typeof(CommandCollection));
StreamReader streamReader = new StreamReader(@"C:\123.xml");
commandscollection = (CommandCollection)dserial.Deserialize(streamReader);
streamReader.Close();
}
어떤 생각이 내가 누락 될 수있다
<?xml version="1.0" encoding="utf-8"?>
<command_strings version="1">
<commands>
<command cmd_id="1" state_id="1" label="On" cmd_type="fixed" cmd_string="1%0D" />
<command cmd_id="1" state_id="3" label="Off" cmd_type="fixed" cmd_string="0%0d" />
</commands>
</command_strings>
내 코드는 다음과 같습니다 다음과 같이
내 XML 읽기? 도움이 될 것입니다.
어떻게 이것이 제대로 작동하지 않는지 공유 할 수 있습니까? – psubsee2003
어떤 이유로 XML 파일에서 XML 속성 값을 가져올 수 없습니다. – Miguel
'@ "C : 123.xml"은 오타가 있습니까? –