M
Marc
I have a C# application which reads through XML Nodes within a MS Word
2003 document. This works fine for fields in the main body, but I'm
having problems retrieving and accessing XML Nodes within the header.
1) I can access nodes in the main body with the following XPath statment:
string m_sXMLNS = xmlns:xsDoc='urn:document_1_0_0-schemas-nextgen-com'";
sXPath = "/xsDocOCUMENT/xsDoc:MACRO[@TYPE='MT_STANDARD']/@NAME";
oAllNodes = oCurrentDoc.SelectNodes(sXPath, m_sXMLNS, false);
I can't find any objects in the header which support SelectNodes.
2) I can cycle through the XML Nodes 'manually', but once I get access
to the node, some of the objects and properties within throw COM
exceptions. For example, I can set the node text, but cannot get it.
Also, if I look at the oCurrentNode object in the watch window, the
first time I see 'Com Exeption' errors, and the second time it works
fine. It works within the code as well, but only after successfully
viewing it in the watch window.
The error I receive is:
'Error HRESULT E_FAIL has been returned from a call to a COM component.'
Here is a sample of the code:
foreach (MSWord.Section oSection in CurrentDocument.Sections)
{
MSWord.HeaderFooter oHeader =
oSection.Headers[MSWord.WdHeaderFooterIndex.wdHeaderFooterPrimary];
foreach (MSWord.XMLNode oCurrentNode in oHeader.Range.XMLNodes)
{
oCurrentNode.Text = "Sample text"; //This works
string sNodeText = oCurrentNode.Text + "\n"; //Does not work
string sBaseName = oCurrentNode.BaseName; //Does not work
string sNodeValue = oCurrentNode.NodeValue + "\n"; //Does not work
}
}
Do I need to activate the header or the fields within it somehow?
Thanks,
Marc
2003 document. This works fine for fields in the main body, but I'm
having problems retrieving and accessing XML Nodes within the header.
1) I can access nodes in the main body with the following XPath statment:
string m_sXMLNS = xmlns:xsDoc='urn:document_1_0_0-schemas-nextgen-com'";
sXPath = "/xsDocOCUMENT/xsDoc:MACRO[@TYPE='MT_STANDARD']/@NAME";
oAllNodes = oCurrentDoc.SelectNodes(sXPath, m_sXMLNS, false);
I can't find any objects in the header which support SelectNodes.
2) I can cycle through the XML Nodes 'manually', but once I get access
to the node, some of the objects and properties within throw COM
exceptions. For example, I can set the node text, but cannot get it.
Also, if I look at the oCurrentNode object in the watch window, the
first time I see 'Com Exeption' errors, and the second time it works
fine. It works within the code as well, but only after successfully
viewing it in the watch window.
The error I receive is:
'Error HRESULT E_FAIL has been returned from a call to a COM component.'
Here is a sample of the code:
foreach (MSWord.Section oSection in CurrentDocument.Sections)
{
MSWord.HeaderFooter oHeader =
oSection.Headers[MSWord.WdHeaderFooterIndex.wdHeaderFooterPrimary];
foreach (MSWord.XMLNode oCurrentNode in oHeader.Range.XMLNodes)
{
oCurrentNode.Text = "Sample text"; //This works
string sNodeText = oCurrentNode.Text + "\n"; //Does not work
string sBaseName = oCurrentNode.BaseName; //Does not work
string sNodeValue = oCurrentNode.NodeValue + "\n"; //Does not work
}
}
Do I need to activate the header or the fields within it somehow?
Thanks,
Marc