问题描述
我试图将以下属性(xmlns:xsi和xsi:type)添加到节点
(Grantee),如下所示:
< Grantee xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance"
xsi:type =" Group">
< URI> http://acs.amazonaws.com/groups/s3/LogDelivery< / URI>
< / Grantee>
但是我不清楚如何添加这些类型的属性。以下
似乎无法正常工作。
Scott
XmlNode属性;
attribute = doc.CreateNode(XmlNodeType.Attribute," xsi:type","");
attribute.Value =" Group";
grantee.Attributes.SetNamedItem(attribute);
attribute = doc.CreateNode(XmlNodeType.Attribute," xmlns:xsi","");
attribute.Value =" http://www.w3.org/2001/XMLSchema-instance" ;;
grantee.Attributes.SetNamedItem(attribute);
Ia??m trying to add the following attributes (xmlns:xsi and xsi:type) to a node
(Grantee) like the following:
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="Group">
<URI>http://acs.amazonaws.com/groups/s3/LogDelivery</URI>
</Grantee>
However I am unclear on how to add these types of attributes. The following
doesn''t seem to work.
Scott
XmlNode attribute;
attribute = doc.CreateNode(XmlNodeType.Attribute, "xsi:type", "");
attribute.Value = "Group";
grantee.Attributes.SetNamedItem(attribute);
attribute = doc.CreateNode(XmlNodeType.Attribute, "xmlns:xsi", "");
attribute.Value = "http://www.w3.org/2001/XMLSchema-instance";
grantee.Attributes.SetNamedItem(attribute);
推荐答案
而不是做grantee.Attributes.SetNamedItem(属性);
做grantee.Attributes.append(属性);
instead of doing grantee.Attributes.SetNamedItem(attribute);
do grantee.Attributes.append(attribute);
对不起doc.CreateNode,它应该是doc.CreateAttribute()
Sorry also instead of doc.CreateNode, it should be doc.CreateAttribute()
对不起doc.CreateNode,它应该是doc.CreateAttribute()
Sorry also instead of doc.CreateNode, it should be doc.CreateAttribute()
这篇关于将属性添加到节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!