XStreamingElement 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 XStreamingElement 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| XStreamingElement(XName) | |
| XStreamingElement(XName, Object) |
初始化一個以指定名稱和內容的新類別實例 XStreamingElement 。 |
| XStreamingElement(XName, Object[]) |
初始化一個以指定名稱和內容的新類別實例 XStreamingElement 。 |
備註
查詢在序列化前 XStreamingElement 不會重複。 這與對 內容進行查詢 XElement不同,後者在構建新 XElement時重複查詢。
關於可傳遞給此建構子的有效內容細節,請參見 XElement 與 XDocument 物件的有效內容。
XStreamingElement(XName)
public:
XStreamingElement(System::Xml::Linq::XName ^ name);
public XStreamingElement(System.Xml.Linq.XName name);
new System.Xml.Linq.XStreamingElement : System.Xml.Linq.XName -> System.Xml.Linq.XStreamingElement
Public Sub New (name As XName)
參數
範例
XElement srcTree = new XElement("Root",
new XElement("Child", 1),
new XElement("Child", 2),
new XElement("Child", 3),
new XElement("Child", 4),
new XElement("Child", 5)
);
XStreamingElement dstTree = new XStreamingElement("NewRoot",
from el in srcTree.Elements()
where (int)el >= 3
select new XElement("DifferentChild", (int)el)
);
Console.WriteLine(dstTree);
Dim srcTree As XElement = _
<Root>
<Child>1</Child>
<Child>2</Child>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot", _
From el In srcTree.Elements _
Where el.Value >= 3 _
Select <DifferentChild><%= el.Value %></DifferentChild> _
)
Console.WriteLine(dstTree)
此範例會產生下列輸出:
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
備註
這個建構子會建立一個沒有內容也沒有屬性的串流元素。
字串 XName隱式轉換為 。 此建構子的典型用途是指定一個字串作為參數,而非建立新的 XName參數。
另請參閱
適用於
XStreamingElement(XName, Object)
初始化一個以指定名稱和內容的新類別實例 XStreamingElement 。
public:
XStreamingElement(System::Xml::Linq::XName ^ name, System::Object ^ content);
public XStreamingElement(System.Xml.Linq.XName name, object content);
public XStreamingElement(System.Xml.Linq.XName name, object? content);
new System.Xml.Linq.XStreamingElement : System.Xml.Linq.XName * obj -> System.Xml.Linq.XStreamingElement
Public Sub New (name As XName, content As Object)
參數
- content
- Object
元素的內容物。
範例
此範例使用以下 XML 檔案,名為 Source.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<Child Key="01">
<GrandChild>aaa</GrandChild>
</Child>
<Child Key="02">
<GrandChild>bbb</GrandChild>
</Child>
<Child Key="03">
<GrandChild>ccc</GrandChild>
</Child>
</Root>
備註
此建構器會建立包含指定內容與屬性的串流元素。
字串 XName隱式轉換為 。 此建構子的典型用途是指定一個字串作為參數,而非建立新的 XName參數。
查詢在序列化前 XStreamingElement 不會重複。 這與對 內容進行查詢 XElement不同,後者在構建新 XElement時重複查詢。
關於可傳遞給此建構子的有效內容細節,請參見 XElement 與 XDocument 物件的有效內容。
另請參閱
適用於
XStreamingElement(XName, Object[])
初始化一個以指定名稱和內容的新類別實例 XStreamingElement 。
public:
XStreamingElement(System::Xml::Linq::XName ^ name, ... cli::array <System::Object ^> ^ content);
public XStreamingElement(System.Xml.Linq.XName name, params object[] content);
public XStreamingElement(System.Xml.Linq.XName name, params object?[] content);
new System.Xml.Linq.XStreamingElement : System.Xml.Linq.XName * obj[] -> System.Xml.Linq.XStreamingElement
Public Sub New (name As XName, ParamArray content As Object())
參數
- content
- Object[]
元素的內容物。
範例
此範例使用以下 XML 檔案,名為 Source.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<Child Key="01">
<GrandChild>aaa</GrandChild>
</Child>
<Child Key="02">
<GrandChild>bbb</GrandChild>
</Child>
<Child Key="03">
<GrandChild>ccc</GrandChild>
</Child>
</Root>
備註
此建構器會建立包含指定內容與屬性的串流元素。
字串 XName隱式轉換為 。 此建構子的典型用途是指定一個字串作為參數,而非建立新的 XName參數。
查詢在序列化前 XStreamingElement 不會重複。 這與對 內容進行查詢 XElement不同,後者在構建新 XElement時重複查詢。
關於可傳遞給此函式的有效內容細節,請參見 XElement 與 XDocument 物件的有效內容。