C
Chango V.
Hello,
We ran into a pretty severe bug. If you switch between the main document
story and another one, for example footnotes, and depending on the current
view state of the document window, creating XML markup may not work
properly. In particular, the XMLNodes.Add method returns an element
different from the one it has created. The following macro demonstrates one
instance of the problem:
Sub DocStoriesXMLBug()
Dim doc As New Document
ns = "urn:xxx.org/schemas/StdMasterChapter-WxS"
' any namespace registered in Word's Schema Library
doc.XMLSchemaReferences.Add ns
Application.TaskPanes(wdTaskPaneXMLStructure).Visible = True
' This step is critical! Without it, the problem doesn't show up
right away.
Dim fn As Footnote
Set fn = doc.Footnotes.Add(doc.Range(), , "Footnote text")
fn.Range.Words(2).XMLNodes.Add "ep", ns
' Substitute "ep" with any element from the chosen schema
fn.Range.Words(1).XMLNodes.Add("ep", ns).Range.Select
'**The bug: The element created should be around the first footnote
word and its
' range should get selected. However, the Add method returns the
element created
' around the second word!
End Sub
Extensive experimentation shows that whether the XML Structure task pane is
visible and what it currently displays somehow triggers the problem. It can
happen even when trying to create markup in the main document story: If the
selection (insertion point) is within a footnote, say, and the XML Structure
is visible, any code trying to create markup in the main document story at
that point is likely to fail. The other required conditions seems to be that
there has to be another element following the new one created. (That's why
the macro above marks up the two footnote words in reverse order.) Further,
if you have the XML Structure view open while the selection is within one
document story and then close the XML Structure view and move the selection
to another document story and try to create markup there, the problem will
show up. Essentially, the XML Structure view has to be visible in order for
it to trigger some state change inside Word so that markup can be created
normally.
I hope someone will have a suggestion for an effective workaround and that
MS folks will look into the problem and find out the root cause. Any help
will be appreciated.
Thanks.
// Chango V.
NOTE: This post is from an anti-spam, non-existent email address. For
further communication, please reply to the Newsgroup and/or contact me
directly at (e-mail address removed).
We ran into a pretty severe bug. If you switch between the main document
story and another one, for example footnotes, and depending on the current
view state of the document window, creating XML markup may not work
properly. In particular, the XMLNodes.Add method returns an element
different from the one it has created. The following macro demonstrates one
instance of the problem:
Sub DocStoriesXMLBug()
Dim doc As New Document
ns = "urn:xxx.org/schemas/StdMasterChapter-WxS"
' any namespace registered in Word's Schema Library
doc.XMLSchemaReferences.Add ns
Application.TaskPanes(wdTaskPaneXMLStructure).Visible = True
' This step is critical! Without it, the problem doesn't show up
right away.
Dim fn As Footnote
Set fn = doc.Footnotes.Add(doc.Range(), , "Footnote text")
fn.Range.Words(2).XMLNodes.Add "ep", ns
' Substitute "ep" with any element from the chosen schema
fn.Range.Words(1).XMLNodes.Add("ep", ns).Range.Select
'**The bug: The element created should be around the first footnote
word and its
' range should get selected. However, the Add method returns the
element created
' around the second word!
End Sub
Extensive experimentation shows that whether the XML Structure task pane is
visible and what it currently displays somehow triggers the problem. It can
happen even when trying to create markup in the main document story: If the
selection (insertion point) is within a footnote, say, and the XML Structure
is visible, any code trying to create markup in the main document story at
that point is likely to fail. The other required conditions seems to be that
there has to be another element following the new one created. (That's why
the macro above marks up the two footnote words in reverse order.) Further,
if you have the XML Structure view open while the selection is within one
document story and then close the XML Structure view and move the selection
to another document story and try to create markup there, the problem will
show up. Essentially, the XML Structure view has to be visible in order for
it to trigger some state change inside Word so that markup can be created
normally.
I hope someone will have a suggestion for an effective workaround and that
MS folks will look into the problem and find out the root cause. Any help
will be appreciated.
Thanks.
// Chango V.
NOTE: This post is from an anti-spam, non-existent email address. For
further communication, please reply to the Newsgroup and/or contact me
directly at (e-mail address removed).