F
Fourge
Hi
I have a strange problem.
Background:
I am developing a solution using Word, WordML, SmartDocuments, C#, VS.NET
and .NET Framework 1.1
The scenario is:
I have a Word document saved as XML (let's call it docA.xml). I am using
SmartDocument technology to automate this document. At different points in
time, I want to insert an XML Node that contains a combination of WordML
Element as well as my own custom Elements (lets call this nodeB) - nodeB is
well formed, valid and all namespaces are clearly declared.
Approach 1:
I have approached this firstly by opening docA.xml in an XML editor, opening
nodeB in the same editor and then pasting nodeB at the desired place in
docA.xml. I then save docA.xml and open it in Word and the document is
perfect - ie. it is formatted correctly, no extra markup is added...
Approach 2:
My second approach (which is the one I need to use in my final solution) is
using a CodeBehind class for the Word document that implements
ISmartDocument. With this approach, I obviously use the Word Object Model to
get access to the document and to add or remove content, XML etc. To achieve
my goal, I get the current Range object, set a string variable to the XML
text that constitutes nodeB. I then call Range.InsertXML and pass in nodeB
as a string (as per the documentation). The result is that nodeB is inserted
into the docA.xml, but the formatting (ie. WordML tags) have been tampered
with by Word and therefore the inserted nodeB is quite different to what it
was before insertion. Essentially, Word adds extra paragraph markup, it
indents the text and ignores things like bold styling.
Comment:
I have spent many long nights on this only to arrive at the current
conclusion that Word is doing something under the covers once I have called
the Range.InsertXML method. This is out of my control at the moment and I am
not sure where to go from here. One of the thoughts I am exploring is that
maybe there is another Property of the Range class that instructs Word not to
alter the inserted XML in any way.
Any help would be greatly appreciated.
I have a strange problem.
Background:
I am developing a solution using Word, WordML, SmartDocuments, C#, VS.NET
and .NET Framework 1.1
The scenario is:
I have a Word document saved as XML (let's call it docA.xml). I am using
SmartDocument technology to automate this document. At different points in
time, I want to insert an XML Node that contains a combination of WordML
Element as well as my own custom Elements (lets call this nodeB) - nodeB is
well formed, valid and all namespaces are clearly declared.
Approach 1:
I have approached this firstly by opening docA.xml in an XML editor, opening
nodeB in the same editor and then pasting nodeB at the desired place in
docA.xml. I then save docA.xml and open it in Word and the document is
perfect - ie. it is formatted correctly, no extra markup is added...
Approach 2:
My second approach (which is the one I need to use in my final solution) is
using a CodeBehind class for the Word document that implements
ISmartDocument. With this approach, I obviously use the Word Object Model to
get access to the document and to add or remove content, XML etc. To achieve
my goal, I get the current Range object, set a string variable to the XML
text that constitutes nodeB. I then call Range.InsertXML and pass in nodeB
as a string (as per the documentation). The result is that nodeB is inserted
into the docA.xml, but the formatting (ie. WordML tags) have been tampered
with by Word and therefore the inserted nodeB is quite different to what it
was before insertion. Essentially, Word adds extra paragraph markup, it
indents the text and ignores things like bold styling.
Comment:
I have spent many long nights on this only to arrive at the current
conclusion that Word is doing something under the covers once I have called
the Range.InsertXML method. This is out of my control at the moment and I am
not sure where to go from here. One of the thoughts I am exploring is that
maybe there is another Property of the Range class that instructs Word not to
alter the inserted XML in any way.
Any help would be greatly appreciated.