XStreamingElement.Save Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Serializzare questo elemento di streaming. L'output può essere salvato in un file, un XmlTextWriteroggetto , TextWritero .XmlWriter Facoltativamente, la formattazione (rientro) può essere disabilitata.
Overload
| Nome | Descrizione |
|---|---|
| Save(Stream) |
Restituisce l'oggetto XStreamingElement all'oggetto specificato Stream. |
| Save(TextWriter) |
Serializzare questo elemento di streaming in un oggetto TextWriter. |
| Save(String) |
Serializzare questo elemento di streaming in un file. |
| Save(XmlWriter) |
Serializzare questo elemento di streaming in un oggetto XmlWriter. |
| Save(Stream, SaveOptions) |
Restituisce questo valore XStreamingElement all'oggetto specificato Stream, specificando facoltativamente il comportamento di formattazione. |
| Save(TextWriter, SaveOptions) |
Serializzare questo elemento di streaming in un TextWriteroggetto , disabilitando facoltativamente la formattazione. |
| Save(String, SaveOptions) |
Serializzare questo elemento di streaming in un file, disabilitando facoltativamente la formattazione. |
Save(Stream)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Restituisce l'oggetto XStreamingElement all'oggetto specificato 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)
Parametri
Commenti
Il codice XML serializzato verrà rientrato. Tutti gli spazi vuoti non significativi verranno rimossi e verranno aggiunti spazi vuoti aggiuntivi in modo che il codice XML venga rientrato correttamente. Il comportamento di questo metodo è che gli spazi vuoti non significativi non verranno mantenuti.
Se si desidera controllare lo spazio vuoto, usare l'overload di Save che accetta SaveOptions come parametro. Usare l'opzione DisableFormatting per salvare il codice XML non rientrato. In questo modo il writer scriverà tutti gli spazi vuoti esattamente come rappresentati nell'albero XML.
Usare l'opzione OmitDuplicateNamespaces se si desidera rimuovere dichiarazioni di spazio dei nomi duplicate.
Si applica a
Save(TextWriter)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Serializzare questo elemento di streaming in un oggetto 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)
Parametri
- textWriter
- TextWriter
Oggetto TextWriter in cui verrà scritto l'oggetto XStreamingElement .
Esempio
Nell'esempio seguente viene creata un'istanza di un albero XML di origine, quindi viene creata un'istanza XStreamingElement di utilizzando una query sull'albero XML di origine. Scrive quindi l'elemento di streaming in un oggetto 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())
In questo esempio viene generato l'output seguente:
<?xml version="1.0" encoding="utf-16"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
Commenti
Il codice XML serializzato verrà rientrato. Tutti gli spazi vuoti non significativi verranno rimossi e verranno aggiunti spazi vuoti aggiuntivi in modo che il codice XML venga rientrato correttamente. Il comportamento di questo metodo è che i nodi di spazio vuoto non significativi nell'albero XML non verranno mantenuti.
Se si desidera controllare lo spazio vuoto, usare uno degli overload di Save che accettano SaveOptions come parametro. Per altre informazioni, vedere Mantenere lo spazio vuoto durante il caricamento o l'analisi di XML e Mantenere lo spazio vuoto durante la serializzazione.
Vedi anche
Si applica a
Save(String)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Serializzare questo elemento di streaming in un file.
public:
void Save(System::String ^ fileName);
public void Save(string fileName);
member this.Save : string -> unit
Public Sub Save (fileName As String)
Parametri
Esempio
Nell'esempio seguente viene creato un albero XML di streaming. Serializza quindi l'albero XML di streaming in un file.
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"))
In questo esempio viene generato l'output seguente:
<?xml version="1.0" encoding="utf-8"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
Commenti
Il codice XML serializzato verrà rientrato. Tutti gli spazi vuoti non significativi verranno rimossi e verranno aggiunti spazi vuoti aggiuntivi in modo che il codice XML venga rientrato correttamente. Il comportamento di questo metodo è che i nodi di spazio vuoto non significativi nell'albero XML non verranno mantenuti.
Se si desidera controllare lo spazio vuoto, usare uno degli overload di Save che accettano SaveOptions come parametro. Per altre informazioni, vedere Mantenere lo spazio vuoto durante il caricamento o l'analisi di XML e Mantenere lo spazio vuoto durante la serializzazione.
Vedi anche
Si applica a
Save(XmlWriter)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Serializzare questo elemento di streaming in un oggetto 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)
Parametri
Esempio
L'esempio seguente crea un oggetto XStreamingElement e lo scrive in un oggetto 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())
In questo esempio viene generato l'output seguente:
<NewRoot><DifferentChild>5</DifferentChild></NewRoot>
Vedi anche
Si applica a
Save(Stream, SaveOptions)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Restituisce questo valore XStreamingElement all'oggetto specificato Stream, specificando facoltativamente il comportamento di formattazione.
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)
Parametri
- options
- SaveOptions
Oggetto SaveOptions che specifica il comportamento di formattazione.
Commenti
Per impostazione predefinita, options sono impostate su None. Questa opzione rimuoverà tutti gli spazi vuoti superflui e aggiungerà spazi vuoti significativi appropriati in modo che il codice XML sia rientrato correttamente.
Se si desidera salvare codice XML non rientrato, specificare il DisableFormatting flag per options. In questo modo il writer scriverà tutti gli spazi vuoti esattamente come rappresentati nell'albero XML.
Usare l'opzione OmitDuplicateNamespaces se si desidera rimuovere dichiarazioni di spazio dei nomi duplicate.
Si applica a
Save(TextWriter, SaveOptions)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Serializzare questo elemento di streaming in un TextWriteroggetto , disabilitando facoltativamente la formattazione.
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)
Parametri
- textWriter
- TextWriter
Oggetto TextWriter in cui restituire il codice XML.
- options
- SaveOptions
Oggetto SaveOptions che specifica il comportamento di formattazione.
Esempio
Nell'esempio seguente vengono illustrati due usi di questo metodo. Il primo utilizzo mantiene lo spazio vuoto. Il secondo serializza con XStreamingElement la formattazione.
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())
In questo esempio viene generato l'output seguente:
<?xml version="1.0" encoding="utf-16"?><NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<?xml version="1.0" encoding="utf-16"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
Commenti
Se si desidera salvare codice XML non rientrato, specificare il DisableFormatting flag per options. In questo modo il writer scriverà tutti gli spazi vuoti esattamente come rappresentati nell'albero XML.
Se si desidera salvare il codice XML con rientro, non specificare il DisableFormatting flag per options. In questo modo verranno rimossi tutti gli spazi vuoti superflui estranei e si aggiungeranno spazi vuoti significativi appropriati in modo che il codice XML sia rientrato correttamente. Si tratta del comportamento predefinito e del comportamento degli overload dei Save metodi che non accettano options come parametro.
Per altre informazioni, vedere Mantenere lo spazio vuoto durante il caricamento o l'analisi di XML e Mantenere lo spazio vuoto durante la serializzazione.
Vedi anche
Si applica a
Save(String, SaveOptions)
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
- Origine:
- XStreamingElement.cs
Serializzare questo elemento di streaming in un file, disabilitando facoltativamente la formattazione.
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)
Parametri
- options
- SaveOptions
Oggetto SaveOptions che specifica il comportamento di formattazione.
Esempio
Nell'esempio seguente vengono illustrati due usi di questo metodo. Il primo utilizzo mantiene lo spazio vuoto. Il secondo serializza con XStreamingElement la formattazione.
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"))
In questo esempio viene generato l'output seguente:
<?xml version="1.0" encoding="utf-8"?><NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<?xml version="1.0" encoding="utf-8"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
Commenti
Se si desidera salvare codice XML non rientrato, specificare il DisableFormatting flag per options. In questo modo il writer scriverà tutti gli spazi vuoti esattamente come rappresentati nell'albero XML.
Se si desidera salvare il codice XML con rientro, non specificare il DisableFormatting flag per options. In questo modo verranno rimossi tutti gli spazi vuoti superflui estranei e si aggiungeranno spazi vuoti significativi appropriati in modo che il codice XML sia rientrato correttamente. Si tratta del comportamento predefinito e del comportamento degli overload dei Save metodi che non accettano options come parametro.
Per altre informazioni, vedere Mantenere lo spazio vuoto durante il caricamento o l'analisi di XML e Mantenere lo spazio vuoto durante la serializzazione.