none
Using InsertXML with Word 2010 to insert custom XML (i.e. pink tagged XML) RRS feed

  • Question

  • Hello,

     

    I am trying to insert custom XML tags (i.e. pink XML tags from Word 2003) into a Word 2010 document.  I am able to insert them just fine if I manually click on the XML structure pane on the right and click on the XML element.  However, I need to do this problematically using the "insertXML" method.

     

    I found a few similar threads, but none of them had an end-to-end fully working solution documented.

    Here were some similar threads:

    http://social.msdn.microsoft.com/Forums/eu/oxmlsdk/thread/4e723b53-94c3-4ce2-b8e2-35cdc94f3a98

    http://openxmldeveloper.org/discussions/formats/f/13/p/811/2027.aspx#2027

     

    So I tried using the InsertXML to insert the following wordML syntax:

     

     

    <w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xml:space="preserve">
    <w:body>
    	<w:p>
    	<LISRef number= "12" congress= "109" title= "khalid test" url= "http://www.cnn.com/" type= "houseBill" >
    	<w:r>
    	<w:t>
    	</w:t>
    	</w:r>
    	<w:hlink w:dest="http://www.cnn.com/">
    	<w:r>
    	<w:rPr>
    	<w:rStyle w:val="HyperLink"/>
    	</w:rPr>
    	<w:t>test2
    	</w:t>
    	</w:r>
    	</w:hlink>
    	<w:r>
    	<w:t>
    	</w:t>
    	</w:r>
    	</LISRef>
    	</w:p>
    </w:body>
    </w:wordDocument>
    
    


     

     

    It inserts just fine - but the XML tags are not present!  Only the text portion is.

     

    So then, I tried using the OpenXML format and wrapping it in flat package;  and then I converted the custom XML sytanx as well.  The full string passed to InsertXML(...) looked as such:

     

    <pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"> 
    <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml"> 
    <pkg:xmlData> 
    <Relationships  xmlns="http://schemas.openxmlformats.org/package/2006/relationships">  
    <Relationship  Id="rId1"  Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"  Target="word/document.xml"/> 
    </Relationships> 
    </pkg:xmlData> 
    </pkg:part> 
    <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"> 
    <pkg:xmlData> 
    <w:document  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">  
    <w:body> 
    	<w:p w:rsidR="00126E28" w:rsidRDefault="00FB5DD2"> 
    	<w:pPr> 
    	<w:pStyle w:val="BodyText" /> 
    	</w:pPr> 
    	<w:customXml w:uri="crs_report" w:element="LISRef"> 
    	<w:customXmlPr> 
    	<w:attr w:name="congress" w:val="109" /> 
    	<w:attr w:name="number" w:val="12" /> 
    	<w:attr w:name="title" w:val="khalid test" /> 
    	<w:attr w:name="type" w:val="houseBill" /> 
    	<w:attr w:name="url" w:val="http://www.cnn.com" /> 
    	</w:customXmlPr> 
    	<w:r w:rsidR="00126E28"> 
    	<w:t>test2
    	</w:t> 
    	</w:r> 
    	</w:customXml> 
    	</w:p> 
    </w:body> 
    </w:document> 
    </pkg:xmlData> 
    </pkg:part> 
    </pkg:package>
    
    


     

     

     

    Again, no runtime errors, but it doesn't actually insert the XML tag -it again only inserts the text portion.

     

    What am I doing wrong here?  

     

    Thanks in advance - I've been spending way too much time on this problem.

    On a side note:  We are still u sing the old custom XML (pink XML tags), because we have purchased an add-on (from a company called "i4i" which won the lawsuit against Microsoft), which re-inserts the XML tags once the Word 2010 loads up.

     


    Khalid K.

    Tuesday, August 16, 2011 8:43 PM

Answers

  • Hi Khalid K,

    As far as I know, The Word 2007 product distributed by Microsoft after 1/10/2010 will no longer read the Custom XML markup contained within .DOCX, .DOCM, or .XML files. These files will continue to open, but the Custom XML markup tags will be removed. As a result, we can't see the XML tag.
    If your solution does utilize Custom XML Tags, consider re-implementing the solution using Content Controls. Detailed guidance on the use of Content Controls in Word 2007 can be found here. Also note the Word Content Controls Toolkit on CodePlex. The Open XML SDK, of course, is quite useful for getting people up to speed on developing solutions for Word and Open XML.
    Hope this can give you some hint about this problem.
    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Bruce Song Thursday, September 1, 2011 7:48 AM
    Friday, August 19, 2011 6:23 AM