Pascal

Pascal

  • NA
  • 1
  • 0

Create xml document

Jul 16 2009 7:49 AM
Hi all,

i am a newbie in C#, and now i need you help...

i need to create an xmlfile with the following content at the beginning.
 <?xml version="1.0" ?> 

<customStates
xmlns="http://schemas.microsoft.com/09/2005/communicator/customStates"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.microsoft.com/09/2005/communicator/customStates
http://livecommteam/sites/main/ice/Wave%2012%20Docs/CustomActivities.xsd">


how can i do that?

i started with



 
XmlTextWriter textWriter = new XmlTextWriter(xmlfile, null);
 
XmlDocument doc = new XmlDocument();

XmlNode docNode = doc.CreateXmlDeclaration("1.0", "", null);

XmlNode customstate = doc.CreateElement("customStates");

XmlAttribute customstateAttribute = doc.CreateAttribute("xmlns");

customstateAttribute.Value = "http://schemas.microsoft.com/09/2005/communicator/customStates";

customstate.Attributes.Append(customstateAttribute);



customstateAttribute = doc.CreateAttribute("xmlns:xsi");

customstateAttribute.Value = "http://www.w3.org/2001/XMLSchema-instance";

customstate.Attributes.Append(customstateAttribute);



customstateAttribute = doc.CreateAttribute("xsi:schemaLocation");

customstateAttribute.Value =
"http://schemas.microsoft.com/09/2005/communicator/customStates
http://livecommteam/sites/main/ice/Wave%2012%20Docs/CustomActivities.xsd";

customstate.Attributes.Append(customstateAttribute);

doc.AppendChild(docNode);

doc.AppendChild(customstate);

doc.Save(textWriter);

but it doesnt work correctly. the Attribute "xsi:Schemalocation" is not written correctly to the xml files.

How can i do this?

Thanks
Pascal

Answers (1)