unity3d - Declaring XML Namespace at Runtime -


i’m trying write script unity application (written in unityscript) able add nodes xml document @ runtime (using xmldocument class). encountering issues when trying declare 'name' attribute of new node.

i know how can create node namespace outside of default xmlns attribution (in case replacing 'xmlns=' 'name=') match existing markup.

after time on msdn docs assume xmlnamespacemanager or changing default namespace, struggling understand how implement (still pretty new xml in unity / ujs) advice welcome.

many in advance,

ryan

current code:

function start(){  	//automatically loads xml doc save etc  	doc = new xmldocument();  	doc.load(application.datapath + "/objmetatest01.xml");  	  	root = doc.documentelement;  	debug.log("xml root: " + root.name);  	  	nodelist = root.selectnodes("metapipeobject");  	debug.log("***xml log begin ***");  	debug.log("number of objects: " + nodelist.count); //returns total number of mpobjs  	  	for (var = 0; < nodelist.count; i++)  	{  		var node = nodelist[i];  		//debug.log("node name: " + node.attributes["name"].value);  		  	}  	  	//namespace manager add namespace file  	//docnamespace = new xmlnamespacemanager(doc.nametable);  	//docnamespace.addnamespace("name", doc.documentelement.namespaceuri);  	  	//debug.log("doc defaultnamespace: " + docnamespace.defaultnamespace);  	//debug.log("nmsg has 'name' prefix: " + docnamespace.hasnamespace("name"));  	debug.log("***xml log end ***");  }      public function createnewnode(){  	//creates new node new objects  	//will similar replace function written    	//select last mp node add new 1 behind	  	doc.documentelement.removeattribute("xlmns");  	  	var lastobjnode = root.selectsinglenode("metapipeobject[last()]");  	var newobjnode = doc.createelement("metapipeobject", "dogtest");  	  	//create new attribute test  	//var nameattr = doc.createattribute("name");  	//newobjnode.attributes.append(nameattr);  	//"name", "nametest", doc.documentelement.namespaceuri, doc  	  	newobjnode.innerxml = lastobjnode.innerxml; //copy content  	  	root.insertafter(newobjnode, lastobjnode); //add bottom of xml doc  	  	doc.save(application.datapath + "/objmetatest01.xml");  	  	debug.log("new nodes attribute: " + newobjnode.attributes);  	debug.log("new node namespace: " + newobjnode.namespaceuri);  	debug.log("new node name: " + newobjnode.name);  	debug.log("new node is: " + newobjnode.innertext);  }

currently returns

   <metapipeobject xmlns="dogtest">  <filename xmlns="">water_drop.obj</filename>  <description xmlns="">text go here</description>  <health xmlns="">10</health>  <experience xmlns="">10</experience> 

the result wanting:

  <metapipeobject name="dogtest">  <filename>water_drop.obj</filename>  <description>text go here</description>  <health>10</health>  <experience>10</experience> 

check following links help

  1. writing xml using javascript
  2. create well-formed xml javascript

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -