0

I want to create an XML file with folllowing header dynamically.

<?xml version="1.0" encoding="utf-8"?>

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>

How should i create this urlset node.

1
  • Please give more information - are you trying to create an XmlDocument, an XDocument or just the start of an actual file? Commented Jun 25, 2009 at 10:04

1 Answer 1

3

With 3.5, something like:

XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XDocument doc = new XDocument(
    new XDeclaration("1.0", "utf-8", null),
    new XElement(ns + "urlset",
        new XAttribute(XNamespace.Xmlns + "xsi", xsi),
        new XAttribute(xsi + "schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"),
        new XElement(ns + "url")
    )
);
// save/writeto
string s = doc.ToString();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.