xml - How do I create this type of node : <node />? -
i'm using system.xml
namespace of .net framework. know how create normal node
dim doc = new xmldocument() doc.createnode(xmlnodetype.element, "node")
the result : <node>
can't seem find way create node "self closed" ( )
is possible?
first, there specialized methods createelement
create elements you.
second, result of createnode
(or createelement
) node not attached anything. need append document.
dim doc = new xmldocument() dim element = doc.createelement("node") doc.appendchild(element) console.writeline(doc.outerxml)
then prints, you'd expect:
<node />
note not in way bad practice node 'self closed'. in fact, when node has no child nodes, can write in 1 of 2 ways:
<node></node> <node />
and purposes , intents there no difference between two.
there xdocument
class , friends in system.xml.linq
namespace newer. might find them easier work with:
dim doc = new xdocument() doc.add(new xelement("node")) console.writeline(doc)
Comments
Post a Comment