Get WordML XML of the doc from the Document object

D

David Thielen

Hi;

I am 99% certain that there is a way to get the WordML (XML) representation
of the document with a call to the Word COM API. But I can't find it.

Anyone know how to do this?
 
P

Peter Huang [MSFT]

Hi Dave,

Based on my research, the Word Object Modal has a property XML of range to
get less complete xml source, that may be different with the wordml file.
Sub Test()
Debug.Print ThisDocument.Range.XML
End Sub

I did not find a documented API/method to get the whole wordml, as a
workaround, I think you may try to save the document as a xml file first
and then read the xml file back into your program.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=,
I am 99% certain that there is a way to get the WordML (XML) representation
of the document with a call to the Word COM API. But I can't find it.
If you're automating Word, then
objDoc.Range.XML

Note, however, that this won't necessarily return the ENTIRE document, as any
range is just part of the document (a STORY). Depending on how the document is
constructed, some things may not be included in the main document story.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
D

David Thielen

Hi;

Found it - Document.Content.get_XML(false) returns the entire document in
WordML format. What is strange is passing true throws an exception - no idea
why.

Also, I think this call is Word 2003 only - but have not had a chance to
verify that yet.
 
P

Peter Huang [MSFT]

Hi

As the VBA document said,
As it applies to all other objects in the Applies to list.
Returns a String that represents the XML text in the specified object.
expression.XML(DataOnly)
expression Required. An expression that returns one of the objects in
the Applies To list.
DataOnly Optional Boolean. True returns the text of the XML without the
Word XML markup. The default setting is False.

The true is used when to return the dataonly xml.
e.g. if you have attach an XML schema into the Word Document.
You may have a try with the sample in the smart document sdk.
http://www.microsoft.com/downloads/details.aspx?FamilyID=24A557F7-EB06-4A2C-
8F6C-2767B174126F&displaylang=en

You will find the VBA code below will throw exception too, if you did not
attach a schema.
Sub Test()
Debug.Print ThisDocument.Content.XML(True)
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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