문서 구조를 유지하면서 Word 문서에서 텍스트 콘텐츠를 추출하고 싶습니다. This question가 가장 가까이 오며 시작점을 제공합니다. Here is a dummy word document. 나는 그것을 압축을 푼 아래 document.xml
포함 시켰습니다 :Word XML에서 구조화 된 콘텐츠 추출
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14"><w:body><w:p w14:paraId="09AE8A7D" w14:textId="338F199D" w:rsidR="00D8348A" w:rsidRPr="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"><w:pPr><w:pStyle w:val="Title"/><w:rPr><w:sz w:val="40"/><w:szCs w:val="40"/></w:rPr></w:pPr><w:r w:rsidRPr="00987637"><w:rPr><w:sz w:val="40"/><w:szCs w:val="40"/></w:rPr><w:t xml:space="preserve">The </w:t></w:r><w:r w:rsidR="00A6772E"><w:rPr><w:sz w:val="40"/><w:szCs w:val="40"/></w:rPr><w:t>Example Docx</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/></w:p><w:p w14:paraId="0803A50C" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637"/><w:p w14:paraId="0EDF635A" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"><w:pPr><w:pStyle w:val="Heading2"/></w:pPr><w:r><w:t>Introduction</w:t></w:r></w:p><w:p w14:paraId="2AF32AB2" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637"/><w:p w14:paraId="4DB9AE94" w14:textId="6C08452A" w:rsidR="00987637" w:rsidRPr="00987637" w:rsidRDefault="00C52D6C" w:rsidP="00987637"><w:r><w:t>This is the introduction para.</w:t></w:r><w:r w:rsidR="00A6772E" w:rsidRPr="00A6772E"><w:t xml:space="preserve"> </w:t></w:r><w:r w:rsidR="00A6772E"><w:t>Awesome.</w:t></w:r></w:p><w:p w14:paraId="676B3B48" w14:textId="77777777" w:rsidR="00987637" w:rsidRPr="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="17CE18FE" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"><w:pPr><w:pStyle w:val="Heading2"/></w:pPr><w:r><w:t>Chapter 1</w:t></w:r></w:p><w:p w14:paraId="58A187F6" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637"/><w:p w14:paraId="2815D3B5" w14:textId="58856A78" w:rsidR="00C52D6C" w:rsidRPr="00987637" w:rsidRDefault="00C52D6C" w:rsidP="00C52D6C"><w:r><w:t xml:space="preserve">This is the </w:t></w:r><w:r><w:t xml:space="preserve">chapter 1 intro </w:t></w:r><w:r><w:t>para.</w:t></w:r><w:r><w:t xml:space="preserve"> </w:t></w:r><w:r w:rsidR="00A6772E"><w:t>Awesome.</w:t></w:r></w:p><w:p w14:paraId="7010E2CD" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="52D9B766" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"><w:pPr><w:pStyle w:val="Heading3"/></w:pPr><w:r><w:t>Chapter 1.1</w:t></w:r></w:p><w:p w14:paraId="055DB7AC" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="22A2C473" w14:textId="1D3FE489" w:rsidR="00A6772E" w:rsidRPr="00987637" w:rsidRDefault="00A6772E" w:rsidP="00A6772E"><w:r><w:t xml:space="preserve">This is </w:t></w:r><w:r><w:t>section 1.1</w:t></w:r><w:r><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t>text</w:t></w:r><w:r><w:t>. Awesome.</w:t></w:r></w:p><w:p w14:paraId="1F60E111" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="62A6FEE6" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"><w:pPr><w:pStyle w:val="Heading3"/></w:pPr><w:r><w:t xml:space="preserve">Chapter </w:t></w:r><w:r><w:t>1.2</w:t></w:r></w:p><w:p w14:paraId="3B8DA076" w14:textId="77777777" w:rsidR="00987637" w:rsidRPr="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="43519FB7" w14:textId="311F726C" w:rsidR="00987637" w:rsidRDefault="00A6772E" w:rsidP="00987637"><w:r><w:t>This is section 1.</w:t></w:r><w:r><w:t>2</w:t></w:r><w:r><w:t xml:space="preserve"> text. Awesome.</w:t></w:r></w:p><w:p w14:paraId="2D6908F2" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="3189011C" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"><w:pPr><w:pStyle w:val="Heading2"/></w:pPr><w:r><w:t>Chapter 2</w:t></w:r></w:p><w:p w14:paraId="6FFC56CD" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637" w:rsidP="00987637"/><w:p w14:paraId="3E9AE930" w14:textId="329881E3" w:rsidR="00987637" w:rsidRPr="00987637" w:rsidRDefault="00A6772E" w:rsidP="00987637"><w:r><w:t xml:space="preserve">This is </w:t></w:r><w:r><w:t>the c</w:t></w:r><w:r><w:t xml:space="preserve">hapter </w:t></w:r><w:r><w:t>2</w:t></w:r><w:r><w:t xml:space="preserve"> </w:t></w:r><w:r><w:t xml:space="preserve">text. </w:t></w:r><w:r><w:t>Awesome.</w:t></w:r></w:p><w:p w14:paraId="57F0B3DF" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637"/><w:p w14:paraId="48315F42" w14:textId="77777777" w:rsidR="00987637" w:rsidRDefault="00987637"/><w:sectPr w:rsidR="00987637" w:rsidSect="00751697"><w:pgSz w:w="11900" w:h="16840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" 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>
이것은 XML로 읽
library(xml2)
library(magrittr)
doc = read_xml('document.xml')
나는이에서 콘텐츠를 추출하기 위해 다음 단계에 대한 불분명 해요. 나는 시도했다 :
xml_find_all(doc, "/w:body/w:p/w:hyperlink/w:r/w:t") %>% xml_text()
그러나 이것은 아무 것도 반환하지 않는다. 도움에 감사드립니다. 내 목표는 문서 구조 (예 : Title
에서 Heading 1
등등의 트리를 반영하는 열이있는 CSV는 Normal
)을 유지하는 형식으로 텍스트 콘텐츠를 내보내는 것입니다.
---------------------------------------- \
편집 :
Title
-- Heading 2
-- -- para
-- -- Chapter 1
-- -- -- para
-- -- -- Chapter 1.1
-- -- -- -- para
-- -- -- Chapter 1.2
-- -- -- -- para
-- -- Chapter 2
-- -- -- para
내가 JSON (괜찮) 출력에 유연 해요 솔직히 그러나이 약의 문서 구조를 반영 할 필요가 : 내가보기로
예제 문서 구조이다.
문서 구조를 보존하는 * 형식이 무엇을 의미하는지 더 구체적으로 설명해야합니다 *. 그것은 이미 매우 구조화 된 형식 (OOXML)입니다. 테이블/CSV는 근본적으로 나무 구조를 잘 나타내지 않습니다. 아마도 진정한 최종 목표를 밝힌다면 우리는 더 잘 도울 수 있습니다. – kjhughes
사실, 당신의 XPath는'w : document' 루트 요소를 무시하고 문서에 아무 것도 없을 때'w : hyperlink' 요소를 참조하는 것 이상의 다른 이유가 없다면 성공할 수 없습니다. – kjhughes
@kjhughes 문서 구조와 원하는 출력에 대한 질문에 답변 해 주셨습니다. – geotheory