WordprocessingML parsing using XPath, XQuery or XPathNavigator

186 views Asked by At

I am dealing with the word processing ML (Office Word file) using XPath expressions. Due to the nature of bookmarks placed in document, the starting of bookmark may be somewhere else and then the end. So they dont really follow any well formed XML hierarchy, so thats the challenge writing XPath expressions for such bookmarked content to read from document.xml file.

Can someone please help how to handle such unusual XML parsing using XPath? e.g. below table:

    <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="003A3B76">
        <w:bookmarkStart w:id="3" w:name="Table3"/>
    </w:p>
    <w:tbl>
        <w:tblPr>
            <w:tblStyle w:val="TableGrid"/>
            <w:tblW w:w="0" w:type="auto"/>
            <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
        </w:tblPr>
        <w:tblGrid>
            <w:gridCol w:w="533"/>
            <w:gridCol w:w="2148"/>
            <w:gridCol w:w="986"/>
            <w:gridCol w:w="865"/>
            <w:gridCol w:w="4818"/>
        </w:tblGrid>
        <w:tr w:rsidR="003A3B76" w:rsidTr="005666D2">
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="533" w:type="dxa"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="BFBFBF" w:themeFill="background1" w:themeFillShade="BF"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>#</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="2148" w:type="dxa"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="BFBFBF" w:themeFill="background1" w:themeFillShade="BF"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>Name</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="986" w:type="dxa"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="BFBFBF" w:themeFill="background1" w:themeFillShade="BF"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>Age</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="865" w:type="dxa"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="BFBFBF" w:themeFill="background1" w:themeFillShade="BF"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>Weight</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="4818" w:type="dxa"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="BFBFBF" w:themeFill="background1" w:themeFillShade="BF"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>Will</w:t>
                    </w:r>
                </w:p>
            </w:tc>
        </w:tr>
        <w:tr w:rsidR="003A3B76" w:rsidTr="005666D2">
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="533" w:type="dxa"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>2</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="2148" w:type="dxa"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>Nagraj</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="986" w:type="dxa"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>38</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="865" w:type="dxa"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>150lb</w:t>
                    </w:r>
                </w:p>
            </w:tc>
            <w:tc>
                <w:tcPr>
                    <w:tcW w:w="4818" w:type="dxa"/>
                </w:tcPr>
                <w:p w:rsidR="003A3B76" w:rsidRDefault="003A3B76" w:rsidP="005666D2">
                    <w:r>
                        <w:t>Be real</w:t>
                    </w:r>
                </w:p>
            </w:tc>
        </w:tr>
        <w:bookmarkEnd w:id="3"/>
    </w:tbl>

bookmarkEnd is ended here inside table, however not in <tr> or <tc>. and the bookmarkStart is started outside of table. That's the way scenario i have from my tagging. Please help with this. Writing a Xpath expression on this is getting complex, any help with XSLT is also welcome.

0

There are 0 answers