|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Hi,
I'm developing an add-in that must run on all versions of MS Office from 97 up. I need to process an MS doc, the content of which is XML. In MS 2003 I could use doc.XMLNodes to access nodes but i can't use this because its not available in the older versions of Word. In MS 2000, I get the document content, write it out to a file and open this file as an XMLTextReader. I can access the nodes using XML Text Reader LocalName.Equals("nodeNameImLookingFor") . This works fine in MS 2000, but in MS2003, the XML tags are stripped from the content when the document is opened and so this approach does not work. Is there a way that i can do this that will work across all versions. Thanks in advance.
|
|
Hi =?Utf-8?B?dGFydGFuY2xp?=,
[Quoted Text] > I'm developing an add-in that must run on all versions of MS Office from 97 > up. I need to process an MS doc, the content of which is XML. In MS 2003 I > could use doc.XMLNodes to access nodes but i can't use this because its not > available in the older versions of Word. In MS 2000, I get the document > content, write it out to a file and open this file as an XMLTextReader. I can > access the nodes using XML Text Reader > LocalName.Equals("nodeNameImLookingFor") . This works fine in MS 2000, but in > MS2003, the XML tags are stripped from the content when the document is > opened and so this approach does not work. Is there a way that i can do this > that will work across all versions. >
I'm not clear on exactly how these "documents" are generated. Is the XML basically "plain text", or what?
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 :-)
|
|
Hi Cindy,
The documents are MS Word format documents but the text contained in the document is XML (or simple XML "like").
So, if i open one of these documents and select the complete content (using range.text) in Word 2000, then i will see the document content as something like, <tag1>Some text in tag1</tag1><tag2>Some text in tag2</tag2>
However, the problem is that if i open the same document using Word 2003, it seems to strip the tags and i get something like, Some text in tag1Some text in tag2
I can do the following in Word 2003: string1 = doc.XMLNodes(1) ; // string will be "Some text in tag1" string2 = doc.XMLNodes(2) ; // string will be "Some text in tag2" but as i say, for backward compatibility I don't want to use XMLNodes.
Thanks.
"Cindy M." wrote:
[Quoted Text] > Hi =?Utf-8?B?dGFydGFuY2xp?=, > > > I'm developing an add-in that must run on all versions of MS Office from 97 > > up. I need to process an MS doc, the content of which is XML. In MS 2003 I > > could use doc.XMLNodes to access nodes but i can't use this because its not > > available in the older versions of Word. In MS 2000, I get the document > > content, write it out to a file and open this file as an XMLTextReader. I can > > access the nodes using XML Text Reader > > LocalName.Equals("nodeNameImLookingFor") . This works fine in MS 2000, but in > > MS2003, the XML tags are stripped from the content when the document is > > opened and so this approach does not work. Is there a way that i can do this > > that will work across all versions. > > > I'm not clear on exactly how these "documents" are generated. Is the XML > basically "plain text", or what? > > 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 :-) > >
|
|
Hi =?Utf-8?B?dGFydGFuY2xp?=,
Thanks for the clarification. See if this works (if it works in the UI, it can be automated):
1. Tools/OPtions/General. Activate "Confirm conversions on open".
2. Open the document. You should get a prompt about the file type. Choose "plain text".
[Quoted Text] > The documents are MS Word format documents but the text contained in the > document is XML (or simple XML "like"). > > So, if i open one of these documents and select the complete content (using > range.text) in Word 2000, then i will see the document content as something > like, > <tag1>Some text in tag1</tag1><tag2>Some text in tag2</tag2> > > However, the problem is that if i open the same document using Word 2003, it > seems to strip the tags and i get something like, > Some text in tag1Some text in tag2 > > I can do the following in Word 2003: > string1 = doc.XMLNodes(1) ; // string will be "Some text in tag1" > string2 = doc.XMLNodes(2) ; // string will be "Some text in tag2" > but as i say, for backward compatibility I don't want to use XMLNodes. >
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 :-)
|
|
Hi Cindy,
Thanks once again. This option didn't seem to have any effect.
When the document is opened manually in Word 2003, the XML tags are shown in the document with special markers (In 2000, the XML tags just look like plain text).
When the document is opened programatically and the content is retrieved using Range.Text then the tags are missing in 2003 and present in 2000 (I guess this is only to be expected given that they are shown as text in 2000 and not in 2003)
Regardless of the setting of the of "Confirm conversions on open" option I get the same results on opening the document manually in 2003. I see the document with tags visually different to text and I get an error message ( I expect that its unrelated, just because i've no schema attached "Some of the XML attributesin this document no longer exist in the attached schemas. As a result Word has associated them with the new namespace prefixed with "errors[ at ]").
"Cindy M." wrote:
[Quoted Text] > Hi =?Utf-8?B?dGFydGFuY2xp?=, > > Thanks for the clarification. See if this works (if it works in the UI, it can > be automated): > > 1. Tools/OPtions/General. Activate "Confirm conversions on open". > > 2. Open the document. You should get a prompt about the file type. Choose > "plain text". > > > The documents are MS Word format documents but the text contained in the > > document is XML (or simple XML "like"). > > > > So, if i open one of these documents and select the complete content (using > > range.text) in Word 2000, then i will see the document content as something > > like, > > <tag1>Some text in tag1</tag1><tag2>Some text in tag2</tag2> > > > > However, the problem is that if i open the same document using Word 2003, it > > seems to strip the tags and i get something like, > > Some text in tag1Some text in tag2 > > > > I can do the following in Word 2003: > > string1 = doc.XMLNodes(1) ; // string will be "Some text in tag1" > > string2 = doc.XMLNodes(2) ; // string will be "Some text in tag2" > > but as i say, for backward compatibility I don't want to use XMLNodes. > > > > 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 :-) > >
|
|
Hi =?Utf-8?B?dGFydGFuY2xp?=,
[Quoted Text] > Regardless of the setting of the of "Confirm conversions on open" option I > get the same results on opening the document manually in 2003. I see the > document with tags visually different to text >
But are you careful to select "Plain text" as the conversion file type? It sounds as if you're accepting the default "XML"...
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 :-)
|
|
Hi Cindy,
Thanks. I managed to get around the problem. I have control over how the input document (containing the XML) is generated. If I generate this from a string rather than an xml file, the document doesn't treat the xml tags in a special manner (and I can process the same as for 2000 docs).
i.e. I replaced, //rng.InsertFile("file.xml", ref missing, ref missing, ref missing, ref missing); with rng.Text = xmlString;
when generating the input document.
Thanks again for all your help!
"Cindy M." wrote:
[Quoted Text] > Hi =?Utf-8?B?dGFydGFuY2xp?=, > > > Regardless of the setting of the of "Confirm conversions on open" option I > > get the same results on opening the document manually in 2003. I see the > > document with tags visually different to text > > > But are you careful to select "Plain text" as the conversion file type? It > sounds as if you're accepting the default "XML"... > > 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 :-) > >
|
|
|