Page 1 of 1

Reading Hyperlink from Word doc

PostPosted: Thu Mar 02, 2017 10:37 am
by laurenquintanilla

I have an html link in a word doc that points to (
Using the following code,
WordprocessingMLPackage wordMLPackage;

this xml is generated below. I can use xslt to read the hyperlink and its style, but I don't see the URL for the target. How do I get that? Somehow Docx4J.toHTML finds the target, but I don't see where it is getting it from.

<w:document mc:Ignorable="w14 wp14" xmlns:dsp="" xmlns:odx="" xmlns:xdr="" xmlns:odgm="" xmlns:dgm="" xmlns:pic="" xmlns:wp14="" xmlns:ns9="" xmlns:ns12="" xmlns:mc="" xmlns:ns33="" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:ns32="" xmlns:ns17="urn:schemas-microsoft-com:office:excel" xmlns:wp="" xmlns:w15="" xmlns:w14="" xmlns:a="" xmlns:b="" xmlns:c="" xmlns:m="" xmlns:oda="" xmlns:wne="" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:odc="" xmlns:r="" xmlns:ns23="" xmlns:odi="" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="" xmlns:ns21="urn:schemas-microsoft-com:office:powerpoint" xmlns:odq="">
<w:p w:rsidR="00690910" w:rsidP="005C58B0" w:rsidRDefault="001A7177">
<w:pStyle w:val="Heading1"/>
<w:hyperlink w:history="true" r:id="rId6">
<w:r w:rsidRPr="001A7177">
<w:rStyle w:val="Hyperlink"/>
<w:bookmarkStart w:name="_GoBack" w:id="0"/>
<w:bookmarkEnd w:id="0"/>
<w:sectPr w:rsidR="00690910">
<w:pgSz w:w="12240" w:h="15840"/>
<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"/>


Re: Reading Hyperlink from Word doc

PostPosted: Thu Mar 02, 2017 2:33 pm
by jason
It comes from the relationship, w:hyperlink/@r:id

For what its worth, the HTML output uses ...

Probably best to ignore that...

Instead, assuming your hyperlink is in MainDocumentPart mdp, you'll get the Relationship using mdp.getRelationshipsPart().getRelationshipByID(id) where id is the value of w:hyperlink/@r:id. You read that from your P.Hyperlink object. You then read the URL from the Relationship object.