Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

string to xml c#

string test = "<body><head>test header</head></body>";

XmlDocument xmltest = new XmlDocument();
xmltest.LoadXml(test);

XmlNodeList elemlist = xmltest.GetElementsByTagName("head");

string result = elemlist[0].InnerXml; 

//result -> "test header"
Comment

c# parse string to xml

/*
<Names>
    <Name>
        <FirstName>John</FirstName>
        <LastName>Smith</LastName>
    </Name>
    <Name>
        <FirstName>James</FirstName>
        <LastName>White</LastName>
    </Name>
</Names>
*/

XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString); // suppose that myXmlString contains "<Names>...</Names>"

XmlNodeList xnList = xml.SelectNodes("/Names/Name");
foreach (XmlNode xn in xnList)
{
  string firstName = xn["FirstName"].InnerText;
  string lastName = xn["LastName"].InnerText;
  Console.WriteLine("Name: {0} {1}", firstName, lastName);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: fluent assertion exception 
Csharp :: c# list declaration 
Csharp :: .net core copy directory to output 
Csharp :: unity find object by name 
Csharp :: scene switch unity 
Csharp :: unity deactivate component 
Csharp :: c# datagridview rows clear not working 
Csharp :: datatable linq where clause c# 
Csharp :: convert string to jtoken c# 
Csharp :: new ienumerable 
Csharp :: csharp read input from console as array 
Csharp :: how to make button in asp.net to go to other page 
Csharp :: c# foreach object in array json 
Csharp :: split string c# 
Csharp :: c# remove char from string 
Csharp :: wpf toolbar disable overflow 
Csharp :: mvc write to console 
Csharp :: list to ienumerable c# 
Csharp :: detect collision in unity 
Csharp :: how to remove all whitespace from a string in c# 
Csharp :: c# alphabetize a list of string 
Csharp :: c# wpf image source from resource programmatically 
Csharp :: addd to array c# 
Csharp :: c# int 
Csharp :: mvc refresh page from controller 
Csharp :: type or namespace text could not be found unity 
Csharp :: meaning immutable and mutable 
Csharp :: replace multiple characters in string c# 
Csharp :: how set cascade on delete and update in same time in laravel 
Csharp :: c# chunk array 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =