Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
XML
<configuration>
<product>
<pname>Abc_ compname
</pname>
<product>
<pname> pqr_ compname
</pname>
Posted
Updated 20-Mar-17 4:33am
v3
Comments
Maciej Los 20-Mar-17 10:16am    
I do not see company name in you XML data! There's pname only!

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[^]
 
Share this answer
 
Comments
Member 13007431 21-Mar-17 1:30am    
I searched before but i was unable to find the answer thats y i posted question.
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[^]
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 21-Mar-17 9:23am    
5, first two links points to the same destination :)
Maciej Los 21-Mar-17 17:29pm    
Thank you, Karthik.
Link corrected ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900