XWPFDocument中XmlCursor的使用

类名:

org.apache.xmlbeans
Interface XmlCursor

版本:在这里插入图片描述
原xml代码:

<w:p w14:paraId="143E3662" w14:textId="4167FBA7" w:rsidR="001506F2" w:rsidRPr="003F3D89" w:rsidRDefault="001506F2" w:rsidP="001506F2">
<w:pPr>
<w:pStyle w:val="a1"/>
<w:ind w:firstLine="459"/>
<w:rPr>
<w:rFonts w:ascii="宋体" w:hAnsi="宋体"/>
<w:lang w:eastAsia="zh-CN"/>
</w:rPr>
</w:pPr>
<w:r w:rsidRPr="003F3D89">
<w:rPr>
<w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:hint="eastAsia"/>
<w:lang w:eastAsia="zh-CN"/>
</w:rPr>
<w:t>本文</w:t>
</w:r>
</w:p>

运行代码:遍历xmlObject的每一个元素的每一个属性

 public ParagraphChildOrderManager(XWPFParagraph paragraph) {
        //using a cursor to go through the paragraph from top to down
        XmlCursor xmlcursor = paragraph.getCTP().newCursor();
        while (xmlcursor.hasNextToken()) {
            XmlCursor.TokenType tokenType = xmlcursor.toNextToken();
            System.out.println("苏菲亚公主~");
        }
    }

进入while之前的xmlcursor,通过xmlcursor.getObject()方法得到:

<xml-fragment w14:paraId="143E3662" w14:textId="4167FBA7" w:rsidR="001506F2" w:rsidRPr="003F3D89" w:rsidRDefault="001506F2" w:rsidP="001506F2" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" 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:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" 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">
  <w:pPr>
    <w:pStyle w:val="a1"/>
    <w:ind w:firstLine="459"/>
    <w:rPr>
      <w:rFonts w:ascii="宋体" w:hAnsi="宋体"/>
      <w:lang w:eastAsia="zh-CN"/>
    </w:rPr>
  </w:pPr>
  <w:r w:rsidRPr="003F3D89">
    <w:rPr>
      <w:rFonts w:ascii="宋体" w:hAnsi="宋体" w:hint="eastAsia"/>
      <w:lang w:eastAsia="zh-CN"/>
    </w:rPr>
    <w:t>本文</w:t>
  </w:r>
  </xml-fragment>

在sout这行打上断点,tokenType和xmlcursor.getObject()的内容在遍历中按照顺序依次显示为:

tokenType = ATTR <xml-fragment ......>143E3662</xml-fragment>
tokenType = ATTR <xml-fragment ......>4167FBA7</xml-fragment>
tokenType = START
<xml-fragment>
<w:pStyle w:val="a1"/>
  <w:ind w:firstLine="459"/>
  <w:rPr>
    <w:rFonts w:ascii="宋体" w:hAnsi="宋体"/>
    <w:lang w:eastAsia="zh-CN"/>
  </w:rPr>
</xml-fragment>
tokenType = START
<xml-fragment w:val="a1" ....../>
tokenType = ATTR <xml-fragment>a1</xml-fragment>
tokenType = END null
tokenType = START <xml-fragment w:firstLine="459" ....../>
tokenType = ATTR <xml-fragment>459</xml-fragment>
......
<w:rPr>的位置,显示:tokenType = START
</w:rPr>的位置,显示:tokenType = END

相关推荐

  1. vue字典使用

    2024-03-11 19:44:02       54 阅读
  2. vue常见使用

    2024-03-11 19:44:02       44 阅读
  3. uniappglobaldata使用

    2024-03-11 19:44:02       59 阅读
  4. vuewebsocket使用

    2024-03-11 19:44:02       65 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-11 19:44:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-11 19:44:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-11 19:44:02       87 阅读
  4. Python语言-面向对象

    2024-03-11 19:44:02       96 阅读

热门阅读

  1. 聚酰胺12(PA 12&尼龙12)行业调研报告

    2024-03-11 19:44:02       51 阅读
  2. C语言加密汉字、图片

    2024-03-11 19:44:02       35 阅读
  3. 算法-双指针、BFS与图论-1238. 日志统计

    2024-03-11 19:44:02       42 阅读
  4. 搭建双节点clickhouse

    2024-03-11 19:44:02       39 阅读
  5. 如何在程序中写一个日志程序,linux,c++

    2024-03-11 19:44:02       48 阅读
  6. AI辅助研发:引领科技创新的未来之路

    2024-03-11 19:44:02       50 阅读
  7. JVM内存结构

    2024-03-11 19:44:02       39 阅读
  8. Kafka - This server does not host this topic-partition

    2024-03-11 19:44:02       40 阅读
  9. TensorFlow简要介绍

    2024-03-11 19:44:02       39 阅读
  10. 掌握uboot使用的2个关键点:命令和环境变量

    2024-03-11 19:44:02       37 阅读