I'm creating a xml-file from code using Linq to XML. The code is prety simple:

XNamespace appvisumnamespace = XNamespace.Get("http://appvisum.com");
            XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                new XComment(""),
                new XElement("AppConfig", new object[] {
                    (from section in this select section.ToXml())
            foreach (XElement e in doc.Root.DescendantsAndSelf())
                if (e.Name.Namespace == XNamespace.None)
                    e.Name = appvisumnamespace.GetName(e.Name.LocalName);

This generates the following output:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<AppConfig xmlns="http://appvisum.com">
  <Section name="Wordpress">
    <Setting name="url" value="Wordpress-Url" />
    <Setting name="username" value="Wordpress-Username" />
    <Setting name="password" value="Wordpress-Password" />
    <Setting name="formuid" value="Wordpress-ForumId" />
  <Section name="AppVisum">
    <Section name="Caching">
      <Setting name="cacheupdateinterval" value="30" />
    <Setting name="test" value="test" />
  <Section name="Blog">
    <Setting name="commentsenabled" value="true" />
    <Setting name="categoriesenabled" value="true" />
  <Section name="Akismet">
    <Setting name="apikey" value="Akismet-API-Key" />
    <Setting name="pageurl" value="PageUrl" />

Now, what I simply want is to change the third line into this:

<AppConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://appvisum.com ../XmlSchemas/AppConfig.xsd" xmlns="http://appvisum.com">

But for some reason I can't seem to do that. I've tried several methods but none of theme worked. Any help would be great. I would like to get this to work without having to turn to old fashion XML-text-writers or string-replacements. There has to be some way to do this.

7 Years
Discussion Span
Last Post by Nemachtiani
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.