Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save hmemcpy/e0b09593dfe34d725b14 to your computer and use it in GitHub Desktop.

Select an option

Save hmemcpy/e0b09593dfe34d725b14 to your computer and use it in GitHub Desktop.

What am I doing wrong here?

var ns = XNamespace.Xmlns + "guid";
var doc = new XDocument(
	new XElement("root",
		new XAttribute(ns, "Guid"),
		new XElement(ns + "MyValue", "{4258b6f1-2c60-4723-8d99-a458d05104b6}")));

// doc.ToString() throws an exception: Prefix "xmlns" is reserved for use by XML.

This is what I want to achieve:

<?xml version="1.0" ?>
<root xmlns:guid="Guid">
    <guid:MyValue>4258b6f1-2c60-4723-8d99-a458d05104b6</guid:MyValue>
</root>
@AviAvni
Copy link
Copy Markdown

AviAvni commented Aug 19, 2015

sorry
var doc = new XDocument(
new XElement("root",
new XAttribute(ns, "guid"),
new XElement(XName.Get("MyValue", "guid"), "{4258b6f1-2c60-4723-8d99-a458d05104b6}")));

@mstrobel
Copy link
Copy Markdown

@jcdickinson nailed it. FYI, Igal, you can also pass the guid value as a System.Guid instead of a string.

@hmemcpy
Copy link
Copy Markdown
Author

hmemcpy commented Aug 19, 2015

@mstrobel I know, but that's for a thing, and the thing has been there since vLegacy, and it has tests around it so... no :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment