XStreamingElement.Save Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Serialice este elemento de streaming. La salida se puede guardar en un archivo, un XmlTextWriter, o TextWriterun XmlWriter. Opcionalmente, el formato (sangría) se puede deshabilitar.
Sobrecargas
| Nombre | Description |
|---|---|
| Save(Stream) |
Genera esto XStreamingElement en el especificado Stream. |
| Save(TextWriter) |
Serialice este elemento de streaming en un TextWriter. |
| Save(String) |
Serialice este elemento de streaming en un archivo. |
| Save(XmlWriter) |
Serialice este elemento de streaming en un XmlWriter. |
| Save(Stream, SaveOptions) |
Genera esto XStreamingElement en el especificado Streamy, opcionalmente, especifica el comportamiento de formato. |
| Save(TextWriter, SaveOptions) |
Serialice este elemento de streaming en , TextWriterdeshabilitando opcionalmente el formato. |
| Save(String, SaveOptions) |
Serialice este elemento de streaming en un archivo, deshabilitando opcionalmente el formato. |
Save(Stream)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Genera esto XStreamingElement en el especificado Stream.
public:
void Save(System::IO::Stream ^ stream);
public void Save(System.IO.Stream stream);
member this.Save : System.IO.Stream -> unit
Public Sub Save (stream As Stream)
Parámetros
Comentarios
El XML serializado se aplicará sangría. Se quitarán todos los espacios en blanco insignificantes y se agregarán espacios en blanco adicionales para que el XML se desendene correctamente. El comportamiento de este método es que no se conservarán espacios en blanco insignificantes.
Si desea controlar el espacio en blanco, use la sobrecarga de Save que toma SaveOptions como parámetro. Use la DisableFormatting opción para guardar XML sin sangría. Esto hará que el escritor escriba todos los espacios en blanco exactamente como se representan en el árbol XML.
Use OmitDuplicateNamespaces la opción si desea quitar declaraciones de espacio de nombres duplicadas.
Se aplica a
Save(TextWriter)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Serialice este elemento de streaming en un TextWriter.
public:
void Save(System::IO::TextWriter ^ textWriter);
public void Save(System.IO.TextWriter textWriter);
member this.Save : System.IO.TextWriter -> unit
Public Sub Save (textWriter As TextWriter)
Parámetros
- textWriter
- TextWriter
que TextWriterXStreamingElement se escribirá en .
Ejemplos
En el ejemplo siguiente se crea un árbol XML de origen y, a continuación, se crea una XStreamingElement instancia de mediante una consulta en el árbol XML de origen. A continuación, escribe el elemento de streaming en .StringWriter
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)
);
StringBuilder sb = new StringBuilder();
dstTree.Save(new StringWriter(sb));
Console.WriteLine(sb.ToString());
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> _
)
Dim sb As StringBuilder = New StringBuilder()
dstTree.Save(New StringWriter(sb))
Console.WriteLine(sb.ToString())
Este ejemplo produce el siguiente resultado:
<?xml version="1.0" encoding="utf-16"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
Comentarios
El XML serializado se aplicará sangría. Se quitarán todos los espacios en blanco insignificantes y se agregarán espacios en blanco adicionales para que el XML se desendene correctamente. El comportamiento de este método es que no se conservarán los nodos de espacio en blanco insignificantes del árbol XML.
Si desea controlar el espacio en blanco, use una de las sobrecargas de Save que toman SaveOptions como parámetro. Para obtener más información, vea Conservar el espacio en blanco al cargar o analizar XML y Conservar el espacio en blanco durante la serialización.
Consulte también
Se aplica a
Save(String)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Serialice este elemento de streaming en un archivo.
public:
void Save(System::String ^ fileName);
public void Save(string fileName);
member this.Save : string -> unit
Public Sub Save (fileName As String)
Parámetros
Ejemplos
En el ejemplo siguiente se crea un árbol XML de streaming. A continuación, serializa el árbol XML de streaming en un archivo.
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)
);
dstTree.Save("Test.xml");
Console.WriteLine(File.ReadAllText("Test.xml"));
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> _
)
dstTree.Save("Test.xml")
Console.WriteLine(File.ReadAllText("Test.xml"))
Este ejemplo produce el siguiente resultado:
<?xml version="1.0" encoding="utf-8"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
Comentarios
El XML serializado se aplicará sangría. Se quitarán todos los espacios en blanco insignificantes y se agregarán espacios en blanco adicionales para que el XML se desendene correctamente. El comportamiento de este método es que no se conservarán los nodos de espacio en blanco insignificantes del árbol XML.
Si desea controlar el espacio en blanco, use una de las sobrecargas de Save que toman SaveOptions como parámetro. Para obtener más información, vea Conservar el espacio en blanco al cargar o analizar XML y Conservar el espacio en blanco durante la serialización.
Consulte también
Se aplica a
Save(XmlWriter)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Serialice este elemento de streaming en un XmlWriter.
public:
void Save(System::Xml::XmlWriter ^ writer);
public void Save(System.Xml.XmlWriter writer);
member this.Save : System.Xml.XmlWriter -> unit
Public Sub Save (writer As XmlWriter)
Parámetros
Ejemplos
En el ejemplo siguiente se crea y XStreamingElement se escribe en .XmlWriter
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)
);
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
using (XmlWriter xw = XmlWriter.Create(sb, xws))
{
XStreamingElement dstTree = new XStreamingElement("NewRoot",
from el in srcTree.Elements()
where (int)el == 5
select new XElement("DifferentChild", (int)el)
);
dstTree.Save(xw);
}
Console.WriteLine(sb.ToString());
Dim srcTree As XElement = _
<Root>
<Child>1</Child>
<Child>2</Child>
<Child>3</Child>
<Child>4</Child>
<Child>5</Child>
</Root>
Dim sb As StringBuilder = New StringBuilder()
Dim xws As XmlWriterSettings = New XmlWriterSettings()
xws.OmitXmlDeclaration = True
Using xw As XmlWriter = XmlWriter.Create(sb, xws)
Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot", _
From el In srcTree.Elements() _
Where el.Value = 5 _
Select <DifferentChild><%= el.Value %></DifferentChild> _
)
dstTree.Save(xw)
End Using
Console.WriteLine(sb.ToString())
Este ejemplo produce el siguiente resultado:
<NewRoot><DifferentChild>5</DifferentChild></NewRoot>
Consulte también
Se aplica a
Save(Stream, SaveOptions)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Genera esto XStreamingElement en el especificado Streamy, opcionalmente, especifica el comportamiento de formato.
public:
void Save(System::IO::Stream ^ stream, System::Xml::Linq::SaveOptions options);
public void Save(System.IO.Stream stream, System.Xml.Linq.SaveOptions options);
member this.Save : System.IO.Stream * System.Xml.Linq.SaveOptions -> unit
Public Sub Save (stream As Stream, options As SaveOptions)
Parámetros
- options
- SaveOptions
Objeto SaveOptions que especifica el comportamiento de formato.
Comentarios
De forma predeterminada, options se establecen en None. Esta opción quitará todos los espacios en blanco insignificantes extraños y agregará espacios en blanco insignificantes adecuados para que el XML esté correctamente sangrado.
Si desea guardar XML sin sangría, especifique la DisableFormatting marca para options. Esto hará que el escritor escriba todos los espacios en blanco exactamente como se representan en el árbol XML.
Use OmitDuplicateNamespaces la opción si desea quitar declaraciones de espacio de nombres duplicadas.
Se aplica a
Save(TextWriter, SaveOptions)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Serialice este elemento de streaming en , TextWriterdeshabilitando opcionalmente el formato.
public:
void Save(System::IO::TextWriter ^ textWriter, System::Xml::Linq::SaveOptions options);
public void Save(System.IO.TextWriter textWriter, System.Xml.Linq.SaveOptions options);
member this.Save : System.IO.TextWriter * System.Xml.Linq.SaveOptions -> unit
Public Sub Save (textWriter As TextWriter, options As SaveOptions)
Parámetros
- textWriter
- TextWriter
objeto TextWriter al que se va a generar el XML.
- options
- SaveOptions
que SaveOptions especifica el comportamiento de formato.
Ejemplos
En el ejemplo siguiente se muestran dos usos de este método. El primer uso conserva el espacio en blanco. La segunda serializa con XStreamingElement formato.
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)
);
StringBuilder sb = new StringBuilder();
dstTree.Save(new StringWriter(sb), SaveOptions.DisableFormatting);
Console.WriteLine(sb.ToString());
Console.WriteLine("------");
sb = new StringBuilder();
dstTree.Save(new StringWriter(sb), SaveOptions.None);
Console.WriteLine(sb.ToString());
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> _
)
Dim sb As StringBuilder = New StringBuilder()
dstTree.Save(New StringWriter(sb), SaveOptions.DisableFormatting)
Console.WriteLine(sb.ToString())
Console.WriteLine("------")
sb = New StringBuilder()
dstTree.Save(New StringWriter(sb), SaveOptions.None)
Console.WriteLine(sb.ToString())
Este ejemplo produce el siguiente resultado:
<?xml version="1.0" encoding="utf-16"?><NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<?xml version="1.0" encoding="utf-16"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
Comentarios
Si desea guardar XML sin sangría, especifique la DisableFormatting marca para options. Esto hará que el escritor escriba todo el espacio en blanco exactamente como se representa en el árbol XML.
Si desea guardar XML con sangría, no especifique la DisableFormatting marca para options. Esto eliminará todos los espacios en blanco insignificantes extraños y agregará espacios en blanco insignificantes apropiados para que el XML esté correctamente sangrado. Este es el comportamiento predeterminado y el comportamiento de las sobrecargas de los Save métodos que no toman options como parámetro.
Para obtener más información, vea Conservar el espacio en blanco al cargar o analizar XML y Conservar el espacio en blanco durante la serialización.
Consulte también
Se aplica a
Save(String, SaveOptions)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
Serialice este elemento de streaming en un archivo, deshabilitando opcionalmente el formato.
public:
void Save(System::String ^ fileName, System::Xml::Linq::SaveOptions options);
public void Save(string fileName, System.Xml.Linq.SaveOptions options);
member this.Save : string * System.Xml.Linq.SaveOptions -> unit
Public Sub Save (fileName As String, options As SaveOptions)
Parámetros
- options
- SaveOptions
Objeto SaveOptions que especifica el comportamiento de formato.
Ejemplos
En el ejemplo siguiente se muestran dos usos de este método. El primer uso conserva el espacio en blanco. La segunda serializa con XStreamingElement formato.
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)
);
dstTree.Save("Test1.xml", SaveOptions.DisableFormatting);
dstTree.Save("Test2.xml", SaveOptions.None);
Console.WriteLine(File.ReadAllText("Test1.xml"));
Console.WriteLine("------");
Console.WriteLine(File.ReadAllText("Test2.xml"));
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> _
)
dstTree.Save("Test1.xml", SaveOptions.DisableFormatting)
dstTree.Save("Test2.xml", SaveOptions.None)
Console.WriteLine(File.ReadAllText("Test1.xml"))
Console.WriteLine("------")
Console.WriteLine(File.ReadAllText("Test2.xml"))
Este ejemplo produce el siguiente resultado:
<?xml version="1.0" encoding="utf-8"?><NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<?xml version="1.0" encoding="utf-8"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
Comentarios
Si desea guardar XML sin sangría, especifique la DisableFormatting marca para options. Esto hará que el escritor escriba todo el espacio en blanco exactamente como se representa en el árbol XML.
Si desea guardar XML con sangría, no especifique la DisableFormatting marca para options. Esto eliminará todos los espacios en blanco insignificantes extraños y agregará espacios en blanco insignificantes apropiados para que el XML esté correctamente sangrado. Este es el comportamiento predeterminado y el comportamiento de las sobrecargas de los Save métodos que no toman options como parámetro.
Para obtener más información, vea Conservar el espacio en blanco al cargar o analizar XML y Conservar el espacio en blanco durante la serialización.