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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -