C# 这一页上有几个例子——请问,标题的第一个字是什么? <reply success="true">More nodes go here</reply> XmlDocument doc = new XmlDocument(); doc
这一页上有几个例子——请问,标题的第一个字是什么?C# 这一页上有几个例子——请问,标题的第一个字是什么? <reply success="true">More nodes go here</reply> XmlDocument doc = new XmlDocument(); doc,c#,xml,C#,Xml,这一页上有几个例子——请问,标题的第一个字是什么? <reply success="true">More nodes go here</reply> XmlDocument doc = new XmlDocument(); doc.LoadXml("<reply success=\"true\">More nodes go here</reply>"); XmlElement root = doc.DocumentElement; strin
<reply success="true">More nodes go here</reply>
XmlDocument doc = new XmlDocument();
doc.LoadXml("<reply success=\"true\">More nodes go here</reply>");
XmlElement root = doc.DocumentElement;
string s = root.Attributes["success"].Value;
string input = "<reply success=\"true\">More nodes go here</reply>";
using (XmlReader xmlReader = XmlReader.Create(new StringReader(input)))
{
xmlReader.MoveToContent();
string success = xmlReader.GetAttribute("success");
Console.WriteLine(success);
}
using System;
using System.Linq;
using System.Xml.Linq;
class MyClass
{
static void Main(string[] args)
{
XElement xmlcode =
XElement.Parse("<reply success=\"true\">More nodes go </reply>");
var successAttributes =
from attribute in xmlcode.Attributes()
where attribute.Name.LocalName=="success"
select attribute ;
if(successAttributes.Count()>0)
foreach (var sa in successAttributes)
{
Console.WriteLine(sa.Value);
}
Console.ReadLine();
}
}
XmlAttribute a = doc.SelectSingleNode("/reply/@success");
Console.Write(a.Value);
Console.Write(doc.DocumentElement.GetAttribute("success"));
<a foo='true' bar='false'/>
<a bar='false' foo='true'/>
var at =
XElement.Parse("<reply success=\"true\">More nodes go </reply>").Attribute("success");
if (at != null) Console.Write(at.Value);
String strXML = "<reply success=\"true\">More nodes go here</reply>";
using (XmlReader reader = XmlReader.Create(new StringReader(strXML)))
{
reader.ReadToFollowing("reply");
reader.MoveToContent();
string strValue = reader.GetAttribute("success");
Console.WriteLine(strValue);
}
string x="<node1 id='12345'><node2 Name='John'></node2><node3 name='abc'></node3></node1>";
XmlDocument xml = new XmlDocument();
xml.LoadXml(x);
var node = xml.GetElementsByTagName("node3");
xml = new XmlDocument();
xml.LoadXml(nodes[0].OuterXml);
XmlElement root = xml.DocumentElement;
String requiredValue = root.GetAttribute("name");
returns "abc";