How To Add “:” (namespace prefix) in XAttribute Name in Xml

*爱你&永不变心* 提交于 2019-12-12 03:36:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!