且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要C#XML更改帮助

更新时间:2023-11-24 08:57:10

更改XML后,doc.OuterXml将更新字符串. />
After changing your XML, doc.OuterXml will have the updated the String.

XmlDocument doc = new XmlDocument();
            doc.LoadXml(stringXML);
            var fnode = doc.GetElementsByTagName("feature")[0];
            var fval = fnode.Attributes["name"].Value;
            if (fval == "IMAGING_SERVICES")
            {
                var servcnode = doc.GetElementsByTagName("service")[0];
                var namenode = servcnode.Attributes["name"].Value;
                if (namenode == "PRINTING")
                {
                    doc.InnerXml.Replace(namenode, "IMAGING_OPTIONS");
                }
            }

String newXmlString = doc.OuterXml;



newXmlString将具有更新的XML.

您是否也要保存该文档?
然后,您可以使用新的XmlString重新加载文档:
doc.LoadXml(newXmlString);



The newXmlString will have the updated XML.

Do you want to save the doc too?
Then you can reload the doc with the new XmlString :
doc.LoadXml(newXmlString);


我不明白这个问题:您正在使用的DOM中的每个节点和属性都是可修改的.只需查看相关类的帮助即可.

—SA
I don''t event understand the problem: every node and attribute in DOM you''re using is modifiable. Just look at help on related classes.

—SA


一切都按预期进行:
如果从字符串构造了文档之后更改了stringXML,则必须重复doc.LoadXml(stringXML).
如果您对doc进行更改并希望将其显示在stringXML中,则必须再次将doc呈现为字符串.

***的问候,

-MRB
Everything is working as expected:
If you change stringXML after the document has been constructed from the string you would have to repeat doc.LoadXml(stringXML).
If you make changes to doc and want them manifested in stringXML you''d have to render doc to a string again.

Best Regards,

-MRB