我承認在這裏學習,並在序列化和反序列化xml方面取得了進展。反序列化xml元素屬性
我的問題是,如何在下面的XML中訪問URI
?
<address href="/api/juniper/sd/address-management/addresses/98677"
uri="/api/juniper/sd/address-management/addresses/98677">
<name>Any-IPv4</name>
<address-type>ANY_IPV4</address-type>
<description>Predefined any-ipv4 address</description>
<host-name />
<id>98677</id>
</address>
真的不知道如何在我的課中設置它來反序列化它嗎?
我班現在的樣子:
[XmlRoot("address", Namespace = "")]
public class address
{
string _name;
string _editVersion;
string _addressType;
string _ipAddress;
string _description;
string _hostName;
string _zone;
string _addressVersion;
string _definitionType;
string _createdByUserName;
string _lastModifiedByUser;
string _createdTime;
string _lastModifiedTime;
string _id;
[XmlElement(ElementName = "name")]
public string name
{
get { return _name; }
set { _name = value; }
}
[XmlElement(ElementName = "edit-version")]
public string editversion
{
get { return _editVersion; }
set { _editVersion = value; }
}
[XmlElement(ElementName = "address-type")]
public string addresstype
{
get { return _addressType; }
set { _addressType = value; }
}
[XmlElement(ElementName = "ip-address")]
public string ipaddress
{
get { return _ipAddress; }
set { _ipAddress = value; }
}
[XmlElement(ElementName = "description")]
public string description
{
get { return _description; }
set { _description = value; }
}
[XmlElement(ElementName = "host-name")]
public string hostname
{
get { return _hostName; }
set { _hostName = value; }
}
}
提前感謝!
使用[XmlAttribute](http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributeattribute.aspx)屬性。看看[這個SO條目](http://stackoverflow.com/questions/11330643/serialize-property-as-xml-attribute-in-element)。 – pasty