Problem accesing XML Nodes in the document Header

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 = "/xsDoc:DOCUMENT/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
 

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