获取<mc:choice requires =“wps”>(docx4j)</mc:choice>中的数据

时间:2015-02-18 03:40:37

标签: docx4j

这是包含形状的<w:r>的典型结构。

<w:r w:rsidR="00D10BFA">
<w:rPr>
    <w:noProof/>
    <w:lang w:eastAsia="en-PH" />
</w:rPr>
<mc:AlternateContent>
    <mc:Choice Requires="wps">
        <w:drawing>
            <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251660288" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1">
                <wp:simplePos x="0" y="0" />
                <wp:positionH relativeFrom="column">
                    <wp:posOffset>2171700</wp:posOffset>
                </wp:positionH>
                <wp:positionV relativeFrom="paragraph">
                    <wp:posOffset>99203</wp:posOffset>
                </wp:positionV>
                <wp:extent cx="1943100" cy="1714500" />
                <wp:effectExtent l="19050" t="19050" r="19050" b="19050" />
                <wp:wrapNone/>
                <wp:docPr id="2" name="Oval 2" />
                <wp:cNvGraphicFramePr/>
                <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                    <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                        <wps:wsp>
                            <wps:cNvSpPr/>
                            <wps:spPr>
                                <a:xfrm>
                                    <a:off x="0" y="0" />
                                    <a:ext cx="1943100" cy="1714500" />
                                </a:xfrm>
                                <a:prstGeom prst="ellipse">
                                    <a:avLst/>
                                </a:prstGeom>
                                <a:solidFill>
                                    <a:schemeClr val="accent4">
                                        <a:lumMod val="75000" />
                                    </a:schemeClr>
                                </a:solidFill>
                                <a:ln w="28575" cap="sq">
                                    <a:solidFill>
                                        <a:schemeClr val="accent6">
                                            <a:lumMod val="75000" />
                                        </a:schemeClr>
                                    </a:solidFill>
                                </a:ln>
                            </wps:spPr>
                            <wps:style>
                                <a:lnRef idx="2">
                                    <a:schemeClr val="accent1">
                                        <a:shade val="50000" />
                                    </a:schemeClr>
                                </a:lnRef>
                                <a:fillRef idx="1">
                                    <a:schemeClr val="accent1" />
                                </a:fillRef>
                                <a:effectRef idx="0">
                                    <a:schemeClr val="accent1" />
                                </a:effectRef>
                                <a:fontRef idx="minor">
                                    <a:schemeClr val="lt1" />
                                </a:fontRef>
                            </wps:style>
                            <wps:txbx>
                                <w:txbxContent>
                                    <w:p w:rsidR="00D10BFA" w:rsidRDefault="00D10BFA" w:rsidP="00D10BFA">
                                        <w:pPr>
                                            <w:jc w:val="center" />
                                        </w:pPr>
                                        <w:r>
                                            <w:t>THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG.THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG.THEQUICKBROWFA</w:t>
                                        </w:r>
                                    </w:p>
                                </w:txbxContent>
                            </wps:txbx>
                            <wps:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="overflow" horzOverflow="overflow" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" numCol="1" spcCol="0" rtlCol="0" fromWordArt="0" anchor="ctr" anchorCtr="0" forceAA="0" compatLnSpc="1">
                                <a:prstTxWarp prst="textNoShape">
                                    <a:avLst/>
                                </a:prstTxWarp>
                                <a:noAutofit/>
                            </wps:bodyPr>
                        </wps:wsp>
                    </a:graphicData>
                </a:graphic>
            </wp:anchor>
        </w:drawing>
    </mc:Choice>
    <mc:Fallback>
        <w:pict>
            <v:oval id="Oval 2" o:spid="_x0000_s1028" style="position:absolute;margin-left:171pt;margin-top:7.8pt;width:153pt;height:135pt;z-index:251660288;visibility:visible;mso-wrap-style:square;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;v-text-anchor:middle" o:gfxdata="UEsDBBQABgAIAAAAIQC2gziS/gAAAOEBAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbJSRQU7DMBBF&#xA;90jcwfIWJU67QAgl6YK0S0CoHGBkTxKLZGx5TGhvj5O2G0SRWNoz/78n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W0NvbnRlbnRfVHlwZXNdLnhtbFBLAQItABQABgAIAAAAIQA4/SH/1gAAAJQB&#xA;AAALAAAAAAAAAAAAAAAAAC8BAABfcmVscy8ucmVsc1BLAQItABQABgAIAAAAIQB6iRROswIAACAG&#xA;AAAOAAAAAAAAAAAAAAAAAC4CAABkcnMvZTJvRG9jLnhtbFBLAQItABQABgAIAAAAIQAw7yw64AAA&#xA;AAoBAAAPAAAAAAAAAAAAAAAAAA0FAABkcnMvZG93bnJldi54bWxQSwUGAAAAAAQABADzAAAAGgYA&#xA;AAAA&#xA;" fillcolor="#bf8f00 [2407]" strokecolor="#538135 [2409]" strokeweight="2.25pt">
                <v:stroke joinstyle="miter" endcap="square" />
                <v:textbox>
                    <w:txbxContent>
                        <w:p w:rsidR="00D10BFA" w:rsidRDefault="00D10BFA" w:rsidP="00D10BFA">
                            <w:pPr>
                                <w:jc w:val="center" />
                            </w:pPr>
                            <w:r>
                                <w:t>THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG.THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG.THEQUICKBROWFA</w:t>
                            </w:r>
                        </w:p>
                    </w:txbxContent>
                </v:textbox>
            </v:oval>
        </w:pict>
    </mc:Fallback>
</mc:AlternateContent>

它包含rPrmc:AlternateContent。我的问题是,当我尝试r.getContent()时,您会希望有两个元素rPrmc:AlternateContent。但在实际结果中,您只有pict,因为行为如下:r.getContent()仅提取<mc:Fallback>标记内的元素。

我想要的是,我想要检索肯定在<a:graphic>内的<mc:Choice>.<w:drawing>.<wp:anchor>

1 个答案:

答案 0 :(得分:1)

通常,mc元素的存在会导致UnmarshalException,因为根据docx4j中使用的模式,它是无效的内容。

当发生这种情况时,docx4j会通过org/docx4j/jaxb/mc-preprocessor.xslt对内容进行预处理,TC45 final draft通常会选择mc:Fallback内容。

您可以使用各种选项来覆盖此行为:

  • easy:你可以提供自己的xslt,它可以做些不同的事情。查看属性&#34; docx4j.jaxb.JaxbValidationEventHandler&#34;指向其位置
  • 更复杂且完全不受支持:更改XSD以在感兴趣的元素中允许mc名称空间内容,然后使用xsd重新生成相关类
  • 修改jaxb实现本身,以应对标记兼容性机制的工作方式。这将非常酷!

更多信息,Google&#39; office openxml标记兼容性和可扩展性&#39;或试试这个{{3}}。