- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何创建带有节点前缀的 xml 文档,如:
<sphinx:docset>
<sphinx:schema>
<sphinx:field name="subject"/>
<sphinx:field name="content"/>
<sphinx:attr name="published" type="timestamp"/>
</sphinx:schema>
当我尝试运行诸如 new XElement("sphinx:docset")
之类的程序时,出现异常
Unhandled Exception: System.Xml.XmlException: The ':' character, hexadecimal val ue 0x3A, cannot be included in a name.
at System.Xml.XmlConvert.VerifyNCName(String name, ExceptionType exceptionTyp e)
at System.Xml.Linq.XName..ctor(XNamespace ns, String localName)
at System.Xml.Linq.XNamespace.GetName(String localName)
at System.Xml.Linq.XName.Get(String expandedName)
最佳答案
在 LINQ to XML 中非常简单:
XNamespace ns = "sphinx";
XElement element = new XElement(ns + "docset");
或者使“别名”正常工作以使其看起来像您的示例,如下所示:
XNamespace ns = "http://url/for/sphinx";
XElement element = new XElement("container",
new XAttribute(XNamespace.Xmlns + "sphinx", ns),
new XElement(ns + "docset",
new XElement(ns + "schema"),
new XElement(ns + "field", new XAttribute("name", "subject")),
new XElement(ns + "field", new XAttribute("name", "content")),
new XElement(ns + "attr",
new XAttribute("name", "published"),
new XAttribute("type", "timestamp"))));
产生:
<container xmlns:sphinx="http://url/for/sphinx">
<sphinx:docset>
<sphinx:schema />
<sphinx:field name="subject" />
<sphinx:field name="content" />
<sphinx:attr name="published" type="timestamp" />
</sphinx:docset>
</container>
关于c# - XElement namespace (如何?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4985974/
我第一次在 .NET 3.5 中使用 Linq for XML,但我在命名空间方面遇到了一些问题。即,XElement 打印如下:当我只想说 . 这是代码: XNamespace opfNa
请考虑这个 XML: 1000 Nima Agha 1002 Ligha
我的查询返回类型是IEnumerable .如何将结果数据转换为 XElement类型?可能吗?有人可以帮助我理解这一点。 var resQ = from e in docElmnt.Descenda
有没有办法用其他 XElement 有选择地替换 XElement 内容? 我有这个 XML: There is something I want to tell you.[pause=3]
我正在尝试使用 Linq 对 XElement 的子项进行排序,然后将现有的子项替换为已排序。 首先我创建 XElement: XElement WithLinq = new
在尝试添加某个元素之前,如何检查该元素是否存在于给定元素中? 背景:我有一个 XDocument X 作为子元素包含 Flowers 随后包含一个系列每个元素都命名为 Flower。每个 Flower
我有一个为列表对象生成 xml 的函数: public XDocument ToXML() { foreach (var row in this) { var xml
我有一个如下所示的 XML 文档: ..... ..... 我想选择所有 lev
我有一个名为“XUsers”的 XElement,它将包含如下所示的 XML: ...还有另一个 XElement,称为“XTasks”,它将包含如下数据:
我希望创建一个具有多个 XElement 子节点的顶级 XElement,如下所示。 Mike Smith Sam
假设我有以下 xml, ... 现在我想“插入”一个围绕 BeginsWith 子句的子句,所以它看起来像这样, ... 我如何使用 LinqToXml 实现这一点? 我主要做的 Add 方法 whe
我想从 B 中选择 COMMISSION 元素,其中每个 COMMISSION 元素的 ID 值不等于 A COMMISSION 元素。 这是我完整的 Main 方法: static void
我正在解析一个大的 xml 文件。所以我将 XmlReader 与 XElement 结合使用,而不是 XElement.Load()。 我已经从 XmlReader 创建了 XElement 对象,
我正在使用 C# .Net 3.5 并尝试将给定的 xml (XDocument) 转换为一个空的(其中 XElement.IsEmpty 为真)不包含文本值。我尝试将 XElement.Value
这是我的示例 xml: Title of RSS feed LINK Details about the feed en TITLE
我有一段类似下面的 xml: Value1_1 Value1_2 Value2_1 Value2_2 我想要的是生成一个 IEnumerab
给定以下 XML: ...以及对“SomeElement”的 XElement 引用和 XPath“Element1/Element2/@Attribute3”
我无法在迭代节点时删除节点,没关系。´ 我有一个包含 Guid 的列表。 我想删除该 xml 文件中的所有 XElement,其中 XElement 具有该列表的 Guid 那是我的 xml 文件:
我收到以下错误: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable>' to 'System.Collect
我收到以下错误: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable>' to 'System.Collect
我是一名优秀的程序员,十分优秀!