XStreamingElement.Save 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 스트리밍 요소를 직렬화합니다. 출력은 파일, XmlTextWriterTextWriter, a 또는 XmlWriter.에 저장할 수 있습니다. 필요에 따라 서식(들여쓰기)을 사용하지 않도록 설정할 수 있습니다.
오버로드
| Name | Description |
|---|---|
| Save(Stream) |
지정된 .에 출력 XStreamingElement 합니다 Stream. |
| Save(TextWriter) |
이 스트리밍 요소를 .에 TextWriter직렬화합니다. |
| Save(String) |
이 스트리밍 요소를 파일로 직렬화합니다. |
| Save(XmlWriter) |
이 스트리밍 요소를 .에 XmlWriter직렬화합니다. |
| Save(Stream, SaveOptions) |
XStreamingElement 필요에 따라 서식 지정 동작을 지정하여 지정된 Stream값으로 출력합니다. |
| Save(TextWriter, SaveOptions) |
필요에 따라 서식을 사용하지 않도록 설정하여 TextWriter이 스트리밍 요소를 직렬화합니다. |
| Save(String, SaveOptions) |
필요에 따라 서식을 사용하지 않도록 설정하여 이 스트리밍 요소를 파일로 직렬화합니다. |
Save(Stream)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
지정된 .에 출력 XStreamingElement 합니다 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)
매개 변수
설명
직렬화된 XML이 들여쓰기됩니다. 모든 중요하지 않은 공백이 제거되고 XML이 제대로 들여쓰기되도록 추가 공백이 추가됩니다. 이 메서드의 동작은 중요하지 않은 공백이 유지되지 않는다는 것입니다.
공백을 제어하려면 매개 변수로 사용하는 Save 오버로드 SaveOptions 를 사용합니다. 이 DisableFormatting 옵션을 사용하여 인덱싱되지 않은 XML을 저장합니다. 이렇게 하면 작성기가 XML 트리에 표시된 것과 정확하게 모든 공백을 작성하게 됩니다.
중복 네임스페이스 선언을 제거하려면 옵션을 사용합니다 OmitDuplicateNamespaces .
적용 대상
Save(TextWriter)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
이 스트리밍 요소를 .에 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)
매개 변수
- textWriter
- TextWriter
TextWriter 기록 XStreamingElement 될 A입니다.
예제
다음 예제에서는 원본 XML 트리를 만든 다음 원본 XML 트리에서 using 쿼리를 인스턴스화 XStreamingElement 합니다. 그런 다음 스트리밍 요소를 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())
이 예제는 다음과 같은 출력을 생성합니다.
<?xml version="1.0" encoding="utf-16"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
설명
직렬화된 XML이 들여쓰기됩니다. 모든 중요하지 않은 공백이 제거되고 XML이 제대로 들여쓰기되도록 추가 공백이 추가됩니다. 이 메서드의 동작은 XML 트리의 중요하지 않은 공백 노드가 유지되지 않는다는 것입니다.
공백을 제어하려면 매개 변수로 사용하는 Save 오버로드 SaveOptions 중 하나를 사용합니다. 자세한 내용은 XML을 로드하거나 구문 분석하는 동안 공백 유지를 참조하고 직렬화하는 동안 공백을 유지합니다.
추가 정보
적용 대상
Save(String)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
이 스트리밍 요소를 파일로 직렬화합니다.
public:
void Save(System::String ^ fileName);
public void Save(string fileName);
member this.Save : string -> unit
Public Sub Save (fileName As String)
매개 변수
예제
다음 예제에서는 스트리밍 XML 트리를 만듭니다. 그런 다음 스트리밍 XML 트리를 파일로 serialize합니다.
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"))
이 예제는 다음과 같은 출력을 생성합니다.
<?xml version="1.0" encoding="utf-8"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
<DifferentChild>4</DifferentChild>
<DifferentChild>5</DifferentChild>
</NewRoot>
설명
직렬화된 XML이 들여쓰기됩니다. 모든 중요하지 않은 공백이 제거되고 XML이 제대로 들여쓰기되도록 추가 공백이 추가됩니다. 이 메서드의 동작은 XML 트리의 중요하지 않은 공백 노드가 유지되지 않는다는 것입니다.
공백을 제어하려면 매개 변수로 사용하는 Save 오버로드 SaveOptions 중 하나를 사용합니다. 자세한 내용은 XML을 로드하거나 구문 분석하는 동안 공백 유지를 참조하고 직렬화하는 동안 공백을 유지합니다.
추가 정보
적용 대상
Save(XmlWriter)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
이 스트리밍 요소를 .에 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)
매개 변수
예제
다음 예제에서는 만들고 XStreamingElement 에 씁니다 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())
이 예제는 다음과 같은 출력을 생성합니다.
<NewRoot><DifferentChild>5</DifferentChild></NewRoot>
추가 정보
적용 대상
Save(Stream, SaveOptions)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
XStreamingElement 필요에 따라 서식 지정 동작을 지정하여 지정된 Stream값으로 출력합니다.
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)
매개 변수
- options
- SaveOptions
SaveOptions 서식 동작을 지정하는 개체입니다.
설명
기본적으로 이 설정 options 은 .로 None설정됩니다. 이 옵션은 불필요한 공백을 모두 제거하고 XML이 제대로 들여쓰기되도록 적절한 중요하지 않은 공백을 추가합니다.
인덱싱되지 않은 XML을 저장하려면 에 대한 DisableFormatting플래그를 options 지정합니다. 이렇게 하면 작성기가 XML 트리에 표시된 것과 정확하게 모든 공백을 작성하게 됩니다.
중복 네임스페이스 선언을 제거하려면 옵션을 사용합니다 OmitDuplicateNamespaces .
적용 대상
Save(TextWriter, SaveOptions)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
필요에 따라 서식을 사용하지 않도록 설정하여 TextWriter이 스트리밍 요소를 직렬화합니다.
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)
매개 변수
- textWriter
- TextWriter
TextWriter XML을 출력할 형식입니다.
- options
- SaveOptions
서식 동작을 지정하는 A SaveOptions 입니다.
예제
다음 예제에서는 이 메서드의 두 가지 용도를 보여 있습니다. 첫 번째 사용은 공백을 유지합니다. 두 번째는 서식을 사용하여 XStreamingElement 직렬화합니다.
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())
이 예제는 다음과 같은 출력을 생성합니다.
<?xml version="1.0" encoding="utf-16"?><NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<?xml version="1.0" encoding="utf-16"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
설명
인덱싱되지 않은 XML을 저장하려면 에 대한 DisableFormatting플래그를 options 지정합니다. 이렇게 하면 기록기가 XML 트리에 표시된 것과 정확히 같은 모든 공백을 작성하게 됩니다.
들여쓰기된 XML을 저장하려면 에 대한 DisableFormatting플래그를 options 지정하지 마세요. 이렇게 하면 불필요한 공백이 모두 제거되고 XML이 제대로 들여쓰기되도록 적절한 중요하지 않은 공백이 추가됩니다. 이는 기본 동작이며 매개 변수로 사용하지 Save 않는 메서드의 options 오버로드 동작입니다.
자세한 내용은 XML을 로드하거나 구문 분석하는 동안 공백 유지를 참조하고 직렬화하는 동안 공백을 유지합니다.
추가 정보
적용 대상
Save(String, SaveOptions)
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
- Source:
- XStreamingElement.cs
필요에 따라 서식을 사용하지 않도록 설정하여 이 스트리밍 요소를 파일로 직렬화합니다.
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)
매개 변수
- options
- SaveOptions
SaveOptions 서식 동작을 지정하는 개체입니다.
예제
다음 예제에서는 이 메서드의 두 가지 용도를 보여 있습니다. 첫 번째 사용은 공백을 유지합니다. 두 번째는 서식을 사용하여 XStreamingElement 직렬화합니다.
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"))
이 예제는 다음과 같은 출력을 생성합니다.
<?xml version="1.0" encoding="utf-8"?><NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<?xml version="1.0" encoding="utf-8"?>
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
설명
인덱싱되지 않은 XML을 저장하려면 에 대한 DisableFormatting플래그를 options 지정합니다. 이렇게 하면 기록기가 XML 트리에 표시된 것과 정확히 같은 모든 공백을 작성하게 됩니다.
들여쓰기된 XML을 저장하려면 에 대한 DisableFormatting플래그를 options 지정하지 마세요. 이렇게 하면 불필요한 공백이 모두 제거되고 XML이 제대로 들여쓰기되도록 적절한 중요하지 않은 공백이 추가됩니다. 이는 기본 동작이며 매개 변수로 사용하지 Save 않는 메서드의 options 오버로드 동작입니다.
자세한 내용은 XML을 로드하거나 구문 분석하는 동안 공백 유지를 참조하고 직렬화하는 동안 공백을 유지합니다.