스타일이 포함된 WordprocessingML 문서
더 복잡한 WordprocessingML 문서에는 스타일로 서식이 지정된 단락이 있습니다.
WordprocessingML 문서의 구성에 대한 몇 가지 정보를 알아 두면 유용합니다. WordprocessingML 문서는 패키지로 저장됩니다. 패키지에는 여러 부분이 있습니다. 부분은 패키지의 컨텍스트에서 사용될 때 명시적 의미를 갖습니다. 부분은 패키지를 구성하기 위해 함께 압축된 파일입니다. 문서에 스타일로 서식이 지정된 단락이 포함되어 있으면 스타일이 적용된 단락이 포함된 문서 부분이 있습니다. 또한 문서에 의해 참조되는 스타일이 포함된 스타일 부분도 있습니다.
패키지에 액세스할 때 임의의 경로를 사용하는 대신 부분 간 관계를 통해 액세스해야 합니다. 이 문제는 WordprocessingML 문서의 내용 조작 자습서의 범위를 벗어나지만 이 자습서에 포함된 예제 프로그램에서는 올바른 방법을 보여 줍니다.
스타일을 사용하는 문서
WordprocessingML 문서의 모양 항목에서 제공하는 WordML 예제는 매우 단순하지만 다음 문서는 더 복잡합니다. 이 문서에는 스타일로 서식이 지정된 단락이 있습니다. Office Open XML 문서를 구성하는 XML을 보는 가장 쉬운 방법은 Office Open XML 문서 부분을 출력하는 예제를 실행하는 것입니다.
다음 문서에서 첫 번째 단락에는 Heading1 스타일이 있습니다. 기본 스타일이 있는 단락이 많이 있으며 Code 스타일이 있는 단락도 많이 있습니다. 이 문서는 이와 같이 비교적 복잡하기 때문에 LINQ to XML을 사용하여 구문 분석하기가 더 흥미로운 대상입니다.
비기본 스타일이 있는 단락에서 단락 요소에는 w:pPr이라는 자식 요소가 있으며 이 자식 요소에는 w:pStyle이라는 자식 요소가 있습니다. 이 요소에는 스타일 이름이 포함된 w:val 특성이 있습니다. 단락에 기본 스타일이 있으면 단락 요소에 w:p.Pr 자식 요소가 없습니다.
<?xml version="1.0" encoding="utf-8"?>
<w:document
xmlns:ve="https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="https://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp="https://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="https://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:wne="https://schemas.microsoft.com/office/word/2006/wordml">
<w:body>
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Heading1" />
</w:pPr>
<w:r>
<w:t>Parsing WordprocessingML with LINQ to XML</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" />
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0">
<w:r>
<w:t>The following example prints to the console.</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" />
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r>
<w:t>using System;</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRPr="00876F34" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r w:rsidRPr="00876F34">
<w:t>class Program {</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRPr="00876F34" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r w:rsidRPr="00876F34">
<w:t xml:space="preserve"> public static void </w:t>
</w:r>
<w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="place">
<w:r w:rsidRPr="00876F34">
<w:t>Main</w:t>
</w:r>
</w:smartTag>
<w:r w:rsidRPr="00876F34">
<w:t>(string[] args) {</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRPr="00876F34" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r w:rsidRPr="00876F34">
<w:t xml:space="preserve"> Console.WriteLine("Hello World");</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRPr="00876F34" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r w:rsidRPr="00876F34">
<w:t xml:space="preserve"> }</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRPr="00876F34" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r w:rsidRPr="00876F34">
<w:t>}</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" />
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0">
<w:r>
<w:t>This example produces the following output:</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" />
<w:p w:rsidR="00A75AE0" w:rsidRDefault="00A75AE0" w:rsidP="006027C7">
<w:pPr>
<w:pStyle w:val="Code" />
</w:pPr>
<w:r>
<w:t>Hello World</w:t>
</w:r>
</w:p>
<w:sectPr w:rsidR="00A75AE0" w:rsidSect="00A75AE0">
<w:pgSz w:w="12240" w:h="15840" />
<w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0" />
<w:cols w:space="720" />
<w:docGrid w:linePitch="360" />
</w:sectPr>
</w:body>
</w:document>