By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

XML Header

P: n/a
Hi,

I have some XML doc loaded in a C# Web Service.
XmlDocument doc = new XmlDocument();
doc.LoadXml(myDoc);

Code Missing to manipulate header (I would like to replace or manupulate all
these XXXXX):
<mso-XXXXXX productversion="XXXXXX">
<mso-application progid="XXXXX"?>

doc.Save(myNewDoc);

Any idea on how to access and manipulate data within the doc header?

Thanks

vbdev
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


vb6dev2003 wrote:
I have some XML doc loaded in a C# Web Service.
XmlDocument doc = new XmlDocument();
doc.LoadXml(myDoc);

Code Missing to manipulate header (I would like to replace or manupulate all
these XXXXX):
<mso-XXXXXX productversion="XXXXXX">
This simply looks like an element's start tag where the element name is
mso-XXXXXX and where the attribute named productversion has the value
XXXXXX so if you wanted to change the attribute value you could simply use
element.SetAttribute("productversion", "new value")
but to change an element's name you need to create a new element with
the new name and replace the old element with the new one.
<mso-application progid="XXXXX"?>


Are you having processing-instructions in your XML? But that should look
like
<?mso-application progid="XXXXX"?>
If you have such a processing instruction it is modelled as an
XmlProcessingInstruction instance where you can change the Data property
as in

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2004082101.xml");
Console.WriteLine(xmlDocument.OuterXml);
foreach (XmlNode node in xmlDocument.ChildNodes) {
if (node.NodeType == XmlNodeType.ProcessingInstruction) {
XmlProcessingInstruction pi = node as XmlProcessingInstruction;
pi.Data = "name1=\"value 1\" name2=\"value 2\"";
}
}
Console.WriteLine(xmlDocument.OuterXml);

that would change the progid="XXXXX" part.

The name/target of the processing instruction cannot be changed, there
you would need to create a new one with a new name and replace the old
instruction node with the new one.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.