XStreamingElement 建構函式

定義

初始化 XStreamingElement 類別的新執行個體。Initializes a new instance of the XStreamingElement class.

多載

XStreamingElement(XName)

從指定的 XName 初始化 XElement 類別的新執行個體。Initializes a new instance of the XElement class from the specified XName.

XStreamingElement(XName, Object)

使用指定的名稱和內容初始化 XStreamingElement 類別的新執行個體。Initializes a new instance of the XStreamingElement class with the specified name and content.

XStreamingElement(XName, Object[])

使用指定的名稱和內容初始化 XStreamingElement 類別的新執行個體。Initializes a new instance of the XStreamingElement class with the specified name and content.

備註

查詢不會反復進行,直到 XStreamingElement 序列化為止。Queries are not iterated until the XStreamingElement is serialized. 這與針對的內容使用查詢相反 XElement ,其中查詢是在建立新的時進行反覆運算 XElementThis is in contrast to using queries for content for an XElement, where queries are iterated at the time of construction of the new XElement.

如需可傳遞給此函式之有效內容的詳細資訊,請參閱 system.xml.linq.xelement> 和 XDocument 物件的有效內容For details about the valid content that can be passed to this constructor, see Valid Content of XElement and XDocument Objects.

XStreamingElement(XName)

從指定的 XName 初始化 XElement 類別的新執行個體。Initializes a new instance of the XElement class from the specified 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)

參數

name
XName

包含項目名稱的 XNameAn XName that contains the name of the element.

範例

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)  

這個範例會產生下列輸出:This example produces the following output:

<NewRoot>  
  <DifferentChild>3</DifferentChild>  
  <DifferentChild>4</DifferentChild>  
  <DifferentChild>5</DifferentChild>  
</NewRoot>  

備註

此函式會建立沒有內容且沒有屬性的串流元素。This constructor creates a streaming element with no content and no attributes.

從字串到的隱含轉換 XNameThere is an implicit conversion from string to XName. 此函式的一般用法是將字串指定為參數,而不是建立新的 XNameTypical use of this constructor is to specify a string as the parameter instead of creating a new XName.

另請參閱

XStreamingElement(XName, Object)

使用指定的名稱和內容初始化 XStreamingElement 類別的新執行個體。Initializes a new instance of the XStreamingElement class with the specified name and content.

public:
 XStreamingElement(System::Xml::Linq::XName ^ name, System::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

包含項目名稱的 XNameAn XName that contains the element name.

content
Object

元素的內容。The contents of the element.

範例

這個範例會使用下列名為 Source.xml 的 XML 檔案:This example uses the following XML file, named 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>  

備註

此函式會建立具有指定內容和屬性的串流元素。This constructor creates a streaming element with the specified content and attributes.

從字串到的隱含轉換 XNameThere is an implicit conversion from string to XName. 此函式的一般用法是將字串指定為參數,而不是建立新的 XNameTypical use of this constructor is to specify a string as the parameter instead of creating a new XName.

查詢不會反復進行,直到 XStreamingElement 序列化為止。Queries are not iterated until the XStreamingElement is serialized. 這與針對的內容使用查詢相反 XElement ,其中查詢是在建立新的時進行反覆運算 XElementThis is in contrast to using queries for content for an XElement, where queries are iterated at the time of construction of the new XElement.

如需可傳遞給此函式之有效內容的詳細資訊,請參閱 system.xml.linq.xelement> 和 XDocument 物件的有效內容For details about the valid content that can be passed to this constructor, see Valid Content of XElement and XDocument Objects.

另請參閱

XStreamingElement(XName, Object[])

使用指定的名稱和內容初始化 XStreamingElement 類別的新執行個體。Initializes a new instance of the XStreamingElement class with the specified name and content.

public:
 XStreamingElement(System::Xml::Linq::XName ^ name, ... cli::array <System::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

包含項目名稱的 XNameAn XName that contains the element name.

content
Object[]

元素的內容。The contents of the element.

範例

這個範例會使用下列名為 Source.xml 的 XML 檔案:This example uses the following XML file, named 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>  

備註

此函式會建立具有指定內容和屬性的串流元素。This constructor creates a streaming element with the specified content and attributes.

從字串到的隱含轉換 XNameThere is an implicit conversion from string to XName. 此函式的一般用法是將字串指定為參數,而不是建立新的 XNameTypical use of this constructor is to specify a string as the parameter instead of creating a new XName.

查詢不會反復進行,直到 XStreamingElement 序列化為止。Queries are not iterated until the XStreamingElement is serialized. 這與針對的內容使用查詢相反 XElement ,其中查詢是在建立新的時進行反覆運算 XElementThis is in contrast to using queries for content for an XElement, where queries are iterated at the time of construction of the new XElement.

如需可傳遞給此函式之有效內容的詳細資訊,請參閱 system.xml.linq.xelement> 和 XDocument 物件的有效內容For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

另請參閱

適用於