XContainer.Add Metodo

Definizione

Aggiunge il contenuto specificato come figlio a XContainer.

Overload

Add(Object)

Aggiunge il contenuto specificato come figlio del XContainer.

Add(Object[])

Aggiunge il contenuto specificato come figlio del XContainer.

Esempio

L'esempio seguente crea due alberi XML e quindi usa questo metodo per aggiungere i risultati di una query a uno di essi.

XElement srcTree = new XElement("Root",  
    new XElement("Element1", 1),  
    new XElement("Element2", 2),  
    new XElement("Element3", 3),  
    new XElement("Element4", 4),  
    new XElement("Element5", 5)  
);  
XElement xmlTree = new XElement("Root",  
    new XElement("NewElement", "Content")  
);  
xmlTree.Add(  
    from el in srcTree.Elements()  
    where (int)el >= 3  
    select el  
);  
Console.WriteLine(xmlTree);  
Dim srcTree As XElement = _  
        <Root>  
            <Element1>1</Element1>  
            <Element2>2</Element2>  
            <Element3>3</Element3>  
            <Element4>4</Element4>  
            <Element5>5</Element5>  
        </Root>  
Dim xmlTree As XElement = _   
        <Root>  
            <NewElement>Content</NewElement>  
        </Root>  
xmlTree.Add( _  
    From el In srcTree.Elements _  
    Where CInt(el) >= 3 _  
    Select el)  
Console.WriteLine(xmlTree)  

Nell'esempio viene prodotto l'output seguente:

<Root>  
  <NewElement>Content</NewElement>  
  <Element3>3</Element3>  
  <Element4>4</Element4>  
  <Element5>5</Element5>  
</Root>  

Commenti

Questo metodo aggiunge il nuovo contenuto dopo il contenuto esistente di XContainer.

Per informazioni dettagliate sul contenuto valido che può essere passato a questa funzione, vedere Contenuto valido degli oggetti XElement e XDocument.

Questo metodo genererà gli Changed eventi e Changing .

Add(Object)

Source:
XContainer.cs
Source:
XContainer.cs
Source:
XContainer.cs

Aggiunge il contenuto specificato come figlio del XContainer.

public:
 void Add(System::Object ^ content);
public void Add (object content);
public void Add (object? content);
member this.Add : obj -> unit
Public Sub Add (content As Object)

Parametri

content
Object

Oggetto contenuto che include contenuto semplice o una raccolta di oggetti contenuto da aggiungere.

Esempio

L'esempio seguente crea due alberi XML e quindi usa questo metodo per aggiungere un XElement oggetto a uno di essi. Aggiunge anche i risultati di una query LINQ all'albero XML.

XElement srcTree = new XElement("Root",  
    new XElement("Element1", 1),  
    new XElement("Element2", 2),  
    new XElement("Element3", 3),  
    new XElement("Element4", 4),  
    new XElement("Element5", 5)  
);  
XElement xmlTree = new XElement("Root",  
    new XElement("Child1", 1),  
    new XElement("Child2", 2),  
    new XElement("Child3", 3),  
    new XElement("Child4", 4),  
    new XElement("Child5", 5)  
);  
xmlTree.Add(new XElement("NewChild", "new content"));  
xmlTree.Add(  
    from el in srcTree.Elements()  
    where (int)el > 3  
    select el  
);  
// Even though Child9 does not exist in srcTree, the following statement will not  
// throw an exception, and nothing will be added to xmlTree.  
xmlTree.Add(srcTree.Element("Child9"));  
Console.WriteLine(xmlTree);  
Dim srcTree As XElement = _   
        <Root>  
            <Element1>1</Element1>  
            <Element2>2</Element2>  
            <Element3>3</Element3>  
            <Element4>4</Element4>  
            <Element5>5</Element5>  
        </Root>  

Dim xmlTree As XElement = _   
        <Root>  
            <Child1>1</Child1>  
            <Child2>2</Child2>  
            <Child3>3</Child3>  
            <Child4>4</Child4>  
            <Child5>5</Child5>  
        </Root>  

xmlTree.Add(New XElement("NewChild", "new content"))  
xmlTree.Add( _  
    From el In srcTree.Elements() _  
    Where CInt(el) > 3 _  
    Select el _  
)  
' Even though Child9 does not exist in srcTree, the following statement will not  
' throw an exception, and nothing will be added to xmlTree.  
xmlTree.Add(srcTree.<Child9>)  
Console.WriteLine(xmlTree)  

Nell'esempio viene prodotto l'output seguente:

<Root>  
  <Child1>1</Child1>  
  <Child2>2</Child2>  
  <Child3>3</Child3>  
  <Child4>4</Child4>  
  <Child5>5</Child5>  
  <NewChild>new content</NewChild>  
  <Element4>4</Element4>  
  <Element5>5</Element5>  
</Root>  

Commenti

Questo metodo aggiunge il nuovo contenuto dopo il contenuto esistente di XContainer.

Per informazioni dettagliate sul contenuto valido che può essere passato a questa funzione, vedere Contenuto valido degli oggetti XElement e XDocument.

Questo metodo genererà gli Changed eventi e Changing .

Vedi anche

Si applica a

Add(Object[])

Source:
XContainer.cs
Source:
XContainer.cs
Source:
XContainer.cs

Aggiunge il contenuto specificato come figlio del XContainer.

public:
 void Add(... cli::array <System::Object ^> ^ content);
public void Add (params object[] content);
public void Add (params object?[] content);
member this.Add : obj[] -> unit
Public Sub Add (ParamArray content As Object())

Parametri

content
Object[]

Elenco di parametri di oggetti contenuto.

Esempio

L'esempio seguente crea due alberi XML, usa questo metodo per aggiungere un XElement oggetto a uno di essi. Aggiunge anche i risultati di una query LINQ all'albero XML.

XElement srcTree = new XElement("Root",  
    new XElement("Element1", 1),  
    new XElement("Element2", 2),  
    new XElement("Element3", 3),  
    new XElement("Element4", 4),  
    new XElement("Element5", 5)  
);  
XElement xmlTree = new XElement("Root",  
    new XElement("Child1", 1),  
    new XElement("Child2", 2),  
    new XElement("Child3", 3),  
    new XElement("Child4", 4),  
    new XElement("Child5", 5)  
);  
xmlTree.Add(new XElement("NewChild", "new content"));  
xmlTree.Add(  
    from el in srcTree.Elements()  
    where (int)el > 3  
    select el  
);  
// Even though Child9 does not exist in srcTree, the following statement will not  
// throw an exception, and nothing will be added to xmlTree  
xmlTree.Add(srcTree.Element("Child9"));  
Console.WriteLine(xmlTree);  
Dim srcTree As XElement = _   
        <Root>  
            <Element1>1</Element1>  
            <Element2>2</Element2>  
            <Element3>3</Element3>  
            <Element4>4</Element4>  
            <Element5>5</Element5>  
        </Root>  

Dim xmlTree As XElement = _  
        <Root>  
            <Child1>1</Child1>  
            <Child2>2</Child2>  
            <Child3>3</Child3>  
            <Child4>4</Child4>  
            <Child5>5</Child5>  
        </Root>  

xmlTree.Add(New XElement("NewChild", "new content"))  
xmlTree.Add( _  
    From el In srcTree.Elements() _  
    Where CInt(el) > 3 _  
    Select el _  
)  
' Even though Child9 does not exist in srcTree, the following statement will not  
' throw an exception, and nothing will be added to xmlTree  
xmlTree.Add(srcTree.<Child9>)  
Console.WriteLine(xmlTree)  

Nell'esempio viene prodotto l'output seguente:

<Root>  
  <Child1>1</Child1>  
  <Child2>2</Child2>  
  <Child3>3</Child3>  
  <Child4>4</Child4>  
  <Child5>5</Child5>  
  <NewChild>new content</NewChild>  
  <Element4>4</Element4>  
  <Element5>5</Element5>  
</Root>  

Commenti

Questo metodo aggiunge il nuovo contenuto dopo il contenuto esistente di XContainer.

Per informazioni dettagliate sul contenuto valido che può essere passato a questa funzione, vedere Contenuto valido degli oggetti XElement e XDocument.

Questo metodo genererà gli Changed eventi e Changing .

Vedi anche

Si applica a