XStreamingElement 建構函式

定義

初始化 XStreamingElement 類別的新執行個體。

多載

XStreamingElement(XName)

從指定的 XName 初始化 XElement 類別的新執行個體。

XStreamingElement(XName, Object)

使用指定的名稱和內容初始化 XStreamingElement 類別的新執行個體。

XStreamingElement(XName, Object[])

使用指定的名稱和內容初始化 XStreamingElement 類別的新執行個體。

備註

在序列化 之前 XStreamingElement ,不會逐一查看查詢。 這與針對 的內容使用查詢 XElement 相反,其中查詢會在建構新 XElement 時逐一查看。

如需可傳遞至此建構函式之有效內容的詳細資訊,請參閱 XElement 和 XDocument 物件的有效內容

XStreamingElement(XName)

從指定的 XName 初始化 XElement 類別的新執行個體。

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)

參數

name
XName

包含項目名稱的 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)

參數

name
XName

包含項目名稱的 XName

content
Object

元素的內容。

範例

此範例會使用名為 Source.xml 的下列 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())

參數

name
XName

包含項目名稱的 XName

content
Object[]

元素的內容。

範例

此範例會使用名為 Source.xml 的下列 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 物件的有效內容

另請參閱

適用於