问题
i have one xml file and using in silverlight.
doc.Descendants(xamlparent).FirstOrDefault().Add(new XAttribute("x:Class","WorkflowConsoleApplication1.modify"));
but in this ":" hexadecimal cause error.how can i add this hexadecimal in attribute name.is this possible ?.
回答1:
You have to see the URI of the namespace which is mapped to the x
namespace prefix. Check out the top of your XML document, it will contain something like xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
.
Then, you instantiate the XAttribute
using the full XML namespace URI from above like so:
new XAttribute(XName.Get("Class", "http://schemas.microsoft.com/winfx/2006/xaml"), "WorkflowConsoleApplication1.modify")
Further reading:
- XName.Get Method (String, String)
- XML namespace on Wikipedia
来源:https://stackoverflow.com/questions/14496991/how-to-add-namespace-prefix-in-xattribute-name-in-xml