Query on InsertXML API

M

Matt

Dear expert ,

I'm developing an add-in that would bring in word ML content from external
systems and stuff it in the document in the required section . Currently I'm
using the Contentcontrol.Range.InsertXML API to get this content into the
document . However this API only accepts complete Word document XML and not
word ML fragments , currently I'm doing a workaround of having a template
defined from word namespaces and other required content and merge the
fragment to form a complete document before inserting .

Is there a way to include only fragments to document(as long as they are
valid) ? The content are dynamic in nature and building blocks didn't work
quite as good .

Is Office Open XML SDK 2.0 offer any solutions . Any other options ?
 
C

Cindy M.

Hi Matt,
I'm developing an add-in that would bring in word ML content from external
systems and stuff it in the document in the required section . Currently I'm
using the Contentcontrol.Range.InsertXML API to get this content into the
document . However this API only accepts complete Word document XML and not
word ML fragments , currently I'm doing a workaround of having a template
defined from word namespaces and other required content and merge the
fragment to form a complete document before inserting .

Is there a way to include only fragments to document(as long as they are
valid) ? The content are dynamic in nature and building blocks didn't work
quite as good .

InsertXML requires valid WordProcessingML. But for the WordProcessingML to be
truly valid it does require certain declarations at the beginning of the XML.
It doesn't require everything before the <body> tag when you look at the XML
making up a Word document, but it does require the structural tags AND the
namespaces used by any of the elements you're inserting (most often this would
be the namespace for the w: prefix).

Best would certainly be to figure out the minimum you require and append that
to the beginning and end of the XML string you're picking up from the outside
repository/source.

The "Office 2003 XML" book from O'Reilly press has a minimal example which
includes:
- the XML declaration
- the <?mso-application progid="Word.Document" ?> element
- the <w:wordDocument> element, plus the namespace for wordml
- the <body> element

And inside the body element is the definition for the rest of the content.
That's the minimum required for WordProcessingML to be considered "valid" for
inserting into a document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
M

Matt

Thanks Cindy , I agree with you . Would you suggest that I only incorporate
the <w:document> section and the corresponding namespaces and exclude out all
other document parts , like relations , style etc . Wukk the insertXML
operation succeed ?

Appreciate your response .
 
C

Cindy M.

Hi Matt,
Would you suggest that I only incorporate
the <w:document> section and the corresponding namespaces and exclude out all
other document parts , like relations , style etc . Wukk the insertXML
operation succeed ?

About all you can do is test to see what does or doesn't work. You certainly
don't need most of the header stuff (unless the text you want to insert bases on
some of it being present).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top