用xmldocument读取xml后 获取根节点document.FirstChild和获取根元素 document.DocumentElement有啥区别
同理 创建节点createNode和创建元素createElement有啥区别 xmlNode和xmlElement有啥区别晕死了 节点和元素有啥区别啊!!!!
同理 创建节点createNode和创建元素createElement有啥区别 xmlNode和xmlElement有啥区别晕死了 节点和元素有啥区别啊!!!!
调试欢乐多
XmlNode node = doc.CreateNode(XmlNodeType.Comment, "comment", null);
bool b = node is XmlElement; // false一个节点是不是XmlElement可以用XmlNodeType得知。
没明白......意思是备注节点是xmlNode但不是xmlElement ?
所以说Element是Node的扩展,除了Element之外,Attribute(属性)、Text(文本节点)、PI(处理指令)、 Document(文档)等等都是Node。
例如,用Element可以方便的获得Node的属性getAttribute(String attrName)
如果用Node,可以得到一个属性集,还要进一步检索才可得到想要的属性。
XmlNode node = doc.CreateNode(XmlNodeType.Comment, "comment", null);
bool b = node is XmlElement; // false
……一个节点是不是XmlElement可以用XmlNodeType得知。
{
string getNodeName();
// throws DOMException;
string getNodeValue();
// throws DOMException;
void setNodeValue(string nodeValue);
NodeType getNodeType();
Node getParentNode();
NodeList getChildNodes();
Node getFirstChild();
Node getLastChild();
Node getPreviousSibling();
Node getNextSibling();
NamedNodeMap getAttributes();
Document getOwnerDocument();
// throws DOMException;
Node insertBefore(Node newChild, Node refChild);
// throws DOMException;
Node replaceChild(Node newChild, Node oldChild);
// throws DOMException;
Node removeChild(Node oldChild);
// throws DOMException;
Node appendChild(Node newChild);
bool hasChildNodes();
Node cloneNode(bool deep);
}
public interface Element : Node
{
string getTagName();
string getAttribute(string name);
//throws DOMException;
void setAttribute(string name, string value);
//throws DOMException;
void removeAttribute(string name);
Attr getAttributeNode(string name);
//throws DOMException;
Attr setAttributeNode(Attr newAttr);
//throws DOMException;
Attr removeAttributeNode(Attr oldAttr);
NodeList getElementsByTagName(string name);
void normalize();
}
XmlElement element;
element.SetAttribute("name", "value"); //可以添加属性
node.SetAttribute("name", "value"); //报错
<?xml version="1.0" encoding="utf-8" ?>
<phonebank>
<gn nm="grdl" val="个人业务">
<个人余额查询 val="0" nm="gryecx"></个人余额查询>
<个人三日内查询 val="1" nm="grsricx"></个人三日内查询>
</gn>
</phonebank>
其中<phonebank> <gn > <个人余额查询 > <个人三日内查询>都属于节点,节点是属性的开始,每个节点可能包含几个属性.如<个人余额查询>节点中的val和nm都是他的属性,"="后面是属性的值
对于换行的解读也不同, 换行在 ff 中作为了一个 node.