Manipulate XML file
Hi ...
a bit stuck with this ...
in my case, I want to replace the old value with a new value via Dotnet
this is XML view
the value of the sphere is a target to be changed
what I want to do is simple,... replace a "sphere" value with a "plane"
--------------------------------------------------------------------------------------------------- Initial --Load the xml assembly dotNet.loadAssembly "system.xml" --Create an xml document object. xmlDoc=dotNetObject "system.xml.xmlDocument" --Open the file in Max to see the file. filename="C:\\BGtest.xml" -- ((getDir #autoback)+"\\BGtest.xml") --------------------------------------------------------------------------------------------------- Load document --Load the XML file. xmlDoc.load filename --------------------------------------------------------------------------------------------------- read document --Check to make sure the xmlDoc has a root element. docEle=xmlDoc.documentElement clearListener() format "Element Name: %\n\n" docEle.name --Check a target attribute value called name objNameStr=(docEle.ChildNodes.itemOf[0].GetAttributeNode "name").value format "Node Name: %\n\n" objNameStr --Check a target attribute value called class objClassStr=(docEle.ChildNodes.itemOf[0].GetAttributeNode "class").value format "Node class: %\n\n" objClassStr --------------------------------------------------------------------------------------------------- Manipulate document --Want to replace "sphere" to "Plane" but it's doesn't work correctly docEle.ChildNodes.itemOf[0].SetAttributeNode "name" "Plane001" --$.name docEle.ChildNodes.itemOf[0].SetAttributeNode "class" "Plane" --classOf $ as string --------------------------------------------------------------------------------------------------- save and open document xmlDoc.save filename edit filename -- to see the result
so i tried but still not working
any suggestion ?
attached example xml...
thanks
Attachment | Size |
---|---|
xml_targetnone.jpg | 41.12 KB |
bgtest.rar | 167 bytes |
Comments
hi Branko... thanks for some
hi Branko...
thanks for some links and your scripts ;)
correct, I got the point of what I needed...
after checking your script, the problem can be solved
glad to see the results
thank you very much man
...
My pleasure.
BTW using XPath you can easely and fast edit any xml file.
I tried to use it but without luck. Maybe next time :)
bga
sounds a good thing... but I
sounds a good thing...
but I hold information about XPath first.
a new language is enough to make me busy for a while. :D
I'm currently finishing another script, yeah maybe next time.
...
Maybe this method will help
bga
...
Now we need to load xml
According to this u can create new fn for setting new values for docElements with
couple attributes.(similar to "getValueByRootEle" fn) :)
To change let say *Scene_Objects_Count* U can use this
bga
...
Also you can look inside code of *ScriptRun* tool where I used similar method for storing some script settings.
Another useful method can be achived with XPath
bga