修改XML文档 [英] modify XML document
问题描述
我有一个文档XML,我将在VisualBasic中修改.NE
当用户在表单中设置复选框和单选按钮时,我保存此信息并修改文档
我的文件采用以下形式
< opzioni>< opzione nome =" DDR">< item tipo =" prova" label =" Ridotto"> true< / item>< item tipo =" completo" label =" ok"> false< / item>< / opzione>< opzione nome =" SDR">< item tipo =" speed" label =" Veloce"> true< / item>< item tipo =" normal" label =" Normale"> false< / item>< / opzione>< / opzioni
我必须将值True / False修改为TAG< item
xmlDoc.Load(fileName
root = xmlDoc.DocumentElemen
nodeList = root.SelectNodes(" opzione / item"
For I = 0 to nodeList.Count -
elem = nodeList.Item(I
elem.Value = NEWVALUE ****我的代码在这里产生错误***
这是错误消息:
" Impossibile impostare un valore su un nodo di tipo:Element。
谢谢你
cos75
I have a document XML that I would modify in VisualBasic.NE
When the user set the checkbox and radiobutton in a form I save this information and modify a document
My document is in the following form
<opzioni><opzione nome="DDR"><item tipo="prova" label="Ridotto">true</item><item tipo="completo" label="ok">false</item></opzione><opzione nome="SDR"><item tipo="speed" label="Veloce">true</item><item tipo="normal" label="Normale">false</item></opzione></opzioni
I have to modify the value True/False into the TAG <item
xmlDoc.Load(fileName
root = xmlDoc.DocumentElemen
nodeList = root.SelectNodes("opzione/item"
For I = 0 To nodeList.Count -
elem = nodeList.Item(I
elem.Value = NEWVALUE ****My code generate an error here***
This is the error messagge:
"Impossibile impostare un valore su un nodo di tipo: Element.
thank yo
cos75
推荐答案
将产生错误的行改为
elem.InnerXml = NEWVALU
Marinus
Change the line wich generated the error into
elem.InnerXml = NEWVALU
Marinus
使用node.InnerText代替node.Valu
顺便说一句,我不得不让BabelFish给你提供错误信息。
Use node.InnerText instead of node.Valu
By the way, I had to get BabelFish to hep me with your error message.
嗯......两个不同回答,这很好
如果我们有以下XML-cod
< opzione nome =" SDR"> ;< item tipo =" speed" label =" Veloce"> test1< child> ab< / child> test2< / item>< / opzione
InnerText将返回
test1abtest
InnerXml将返回
test1< child> ab< / child> test
使用InnerText设置XML或只要没有XML标签,InnerXml就没有区别(< child>< / child>
InnerText将拧紧这些标签(& lt,& gt)
在给定的情况下,没有区别。
hmm.. Two different answers, that''s nice
If we have the following XML-cod
<opzione nome="SDR"><item tipo="speed" label="Veloce">test1<child>ab</child>test2</item></opzione
InnerText would return
test1abtest
InnerXml would return
test1<child>ab</child>test
Setting XML with InnerText or InnerXml makes no difference as long as there are no XML-tags (<child></child>
InnerText will screw these tags (<,>)
In the given case there''s no difference.
这篇关于修改XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!