注册 登录
编程论坛 Ruby论坛

关于DOMDocument建立节点的问题

kfp_kaka 发布于 2006-03-06 10:52, 4018 次点击

DIM tempdoc as DOMDocument
DIM root as IXMLDOMElement
DIM tempnode as IXMLDOMElement

Set tempdoc = NEW DOMDocument
set root = tempdoc.CreateElement("Personal")
set tempdoc.documentElement = root

set tempnode = tempdoc.CreateNode(NODE_ELEMENT, "Web", "")

请问CreateElement和CreateNode的区别是什么?
CreateNode有那些参数,谢谢!

1 回复
#2
唐伯猫2006-03-13 15:35

XmlElement elem;
elem =XmlDocument.CreateElement("新元素的前缀","新元素的本地名称","新元素的命名空间URL");

Example:

XmlDocument doc = new XmlDocument();
string xmlData = "<book xmlns:bk='urn:samples'></book>";

doc.Load(new StringReader(xmlData));

// Create a new element and add it to the document.
XmlElement elem = doc.CreateElement("bk", "genre", "urn:samples");
elem.InnerText = "fantasy";
doc.DocumentElement.AppendChild(elem);

Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);


XmlNode elem = doc.CreateNode("新节点的XmlNodeType","新节点的限定名","新节点的命名空间URL");

Example:

//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");

//Create a new node and add it to the document.
XmlNode elem = doc.CreateNode(XmlNodeType.Element, "price", null);
elem.InnerText = "19.95";
doc.DocumentElement.AppendChild(elem);

Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);

1