XmlNode.PreviousSibling 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取紧接在该节点之前的节点。
public:
virtual property System::Xml::XmlNode ^ PreviousSibling { System::Xml::XmlNode ^ get(); };
public virtual System.Xml.XmlNode PreviousSibling { get; }
public virtual System.Xml.XmlNode? PreviousSibling { get; }
member this.PreviousSibling : System.Xml.XmlNode
Public Overridable ReadOnly Property PreviousSibling As XmlNode
属性值
前一个 XmlNode
。 如果前面没有节点,则返回 null
。
示例
以下示例显示 XML 文档中的所有书籍。
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
int main()
{
XmlDocument^ doc = gcnew XmlDocument;
doc->Load( "books.xml" );
XmlNode^ lastNode = doc->DocumentElement->LastChild;
Console::WriteLine( "Last book..." );
Console::WriteLine( lastNode->OuterXml );
XmlNode^ prevNode = lastNode->PreviousSibling;
Console::WriteLine( "\r\nPrevious book..." );
Console::WriteLine( prevNode->OuterXml );
}
using System;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");
XmlNode lastNode = doc.DocumentElement.LastChild;
Console.WriteLine("Last book...");
Console.WriteLine(lastNode.OuterXml);
XmlNode prevNode = lastNode.PreviousSibling;
Console.WriteLine("\r\nPrevious book...");
Console.WriteLine(prevNode.OuterXml);
}
}
Imports System.Xml
public class Sample
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.Load("books.xml")
Dim lastNode as XmlNode = doc.DocumentElement.LastChild
Console.WriteLine("Last book...")
Console.WriteLine(lastNode.OuterXml)
Dim prevNode as XmlNode = lastNode.PreviousSibling
Console.WriteLine(ControlChars.LF + "Previous book...")
Console.WriteLine(prevNode.OuterXml)
end sub
end class