如何使用vb.net替换XML中的值的变量。 [英] How to replace a variable with value in XML using vb.net.

查看:73
本文介绍了如何使用vb.net替换XML中的值的变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件,在那个xml文件中我有一个名为compname的变量。当这个compname存在时,我们必须用当前工作的计算机名替换compname。

我该怎么办?



< b>我尝试了什么:



XML文件模式是:

I have one XML file and in that xml file i have one variable called compname. when this compname exists,we have to replace the compname by currently working computer name.
How can i do this??.

What I have tried:

XML file pattern is:

<configuration>
<product>
<pname>Abc_ compname
</pname>
<product>
<pname> pqr_ compname
</pname>

推荐答案

我们不做你的功课你 - 它将帮助你学习。我怎么知道这是作业?因为每年的这个时候我们都会有大量新成员提出这个问题。



首先 - 参考你的课程作业。如果您不知道如何开始这项任务,那么您需要与您的导师讨论。



其次 - 学习如何研究。这种能力可能是你可以从教育中获得的最重要的事情 - 如何找到你需要的信息。



从这里开始操作XML [ ^ ]

这里找出如何获取计算机名称 [ ^ ]

您可能也会从阅读中受益...

代码项目快速解答常见问题解答 [ ^ ]

文章理念:如何不提出问题 [ ^ ]
We don't do your homework for you - it is set to help you learn. How do I know this is homework? Because this time of year we get a flood of new members asking this question.

First - refer to your course work. If you can't any idea of how to start this assignment then you need to discuss this with your tutor.

Secondly - learn how to research. This ability is probably the most important thing you can pick up from education - how to find the information you need.

Start here for manipulating XML[^]
And here to find out how to get the computer name[^]
You will probably also benefit from reading ...
Code Project Quick Answers FAQ[^]
Article Idea: How Not to Ask a Question[^]


首先,请阅读我对这个问题的评论。好像,您必须编写自定义方法来拆分 [ ^ ] 公司名称产品名称来自 pname 节点。



实现这一目标的方法很少。您可以使用:

XDocument类(System.Xml.Linq) [ ^ ]

XmlDocument Class(System.Xml) [ ^ ]

XML序列化 [ ^ ]

来操作xml数据。



对于小部分数据,您可以使用Linq,请参阅:。 NET语言 - XML数据集成查询 [ ^ ]

LINQ - C#中的示例查询,Visual Studio 2010的VB.NET [ ^ ]

在任何其他情况下,我建议使用序列化和反序列化。

XML序列化和反序列化:第1部分 [ ^ ]

XML序列化和反序列化:第2部分 [ ^ ]

自定义类集合序列化和反序列化的完整示例 [ ^ ]
First of all, please read my comment to the question. Seems, you have to write custom method to split[^] company name and product name from pname node.

There's few ways to achieve that. You can use:
XDocument Class (System.Xml.Linq)[^]
XmlDocument Class (System.Xml)[^]
or XML Serialization[^]
to manipulate xml data.

For small portion of data, you can use Linq, see: .NET Language-Integrated Query for XML Data[^]
LINQ - Sample Queries in C#, VB.NET for Visual Studio 2010[^]
In any other case, i'd suggest to use serialization and deserialization.
XML Serialization and Deserialization: Part-1[^]
XML Serialization and Deserialization: Part-2[^]
A Complete Sample of Custom Class Collection Serialization and Deserialization[^]


这篇关于如何使用vb.net替换XML中的值的变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆