Philipp wrote:
I wrote a small c# programm, which generates an xml-string by serializing a
class and sends it to a server. Now I want to change some values in that
xml-string.
The only way for me to do that might be, to deserialize it, change the
particular attribute and serialize it again, to finally save it on my
harddisk.
But I believe, that there is a more convenient way to do this, since it is
also possible to append an element...
If you have a string with an XML document then you need to deserialize
to manipulate that. You can do that as you already seem to do, by
deserializing to an instance object of your class and manipulating the
properties of the object. Or you could use XmlDocument, the DOM
implementation in .NET to do that e.g.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(yourString);
// now find the element whose attribute you want to change e.g.
XmlElement element =
xmlDocument.SelectSingleNode("SomeXPathExpression" ) as XmlElement;
if (element != null) {
element.SetAttribute("attribute-name", "new attribute value");
}
// how serialize to string e.g. using
xmlDocument.OuterXml
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/