XML Navigation and range

  • Thread starter Thread starter JY
  • Start date Start date
J

JY

Hi,

I'm using XMLNavigator to replace a range in an XML file. The code is as
follows:

XPathNavigator navigator = documentXML.CreateNavigator();

XPathNavigator navIRV =
navigator.SelectSingleNode(@"//w:p[w:customXml/@w:element=""My_ID1""]",
namespaceManager);
navIRV.MoveToChild("customXml", wordprocessingML);
navIRV.MoveToChild("r", wordprocessingML);

XmlWriter xmlWriter = navIRV.ReplaceRange(navIRV);
xmlWriter.WriteStartElement("w", "t", wordprocessingML);
xmlWriter.WriteEndElement();
xmlWriter.Close();

While debugging I see that it is getting written properly. However, when I
try to open the created XML file, I see some more data added after the actual
end of the file. Not sure what is going wrong, appreciate any help.

TIA,
JY
 
JY said:
I'm using XMLNavigator to replace a range in an XML file. The code is as
follows:

XPathNavigator navigator = documentXML.CreateNavigator();

XPathNavigator navIRV =
navigator.SelectSingleNode(@"//w:p[w:customXml/@w:element=""My_ID1""]",
namespaceManager);
navIRV.MoveToChild("customXml", wordprocessingML);
navIRV.MoveToChild("r", wordprocessingML);

XmlWriter xmlWriter = navIRV.ReplaceRange(navIRV);
xmlWriter.WriteStartElement("w", "t", wordprocessingML);
xmlWriter.WriteEndElement();
xmlWriter.Close();

While debugging I see that it is getting written properly. However, when I
try to open the created XML file, I see some more data added after the actual
end of the file. Not sure what is going wrong, appreciate any help.

Can you post a minimal but complete XML document you are running that
code against? Are you doing any other operations on the XML before you
call the Save method on documentXML?
 
Back
Top