Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 这一页上有几个例子——请问,标题的第一个字是什么? <reply success="true">More nodes go here</reply> XmlDocument doc = new XmlDocument(); doc_C#_Xml - Fatal编程技术网

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";