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