gpt4 book ai didi

c# - XElement 中的 XML 解析 ':'

转载 作者:太空宇宙 更新时间:2023-11-03 20:28:52 24 4
gpt4 key购买 nike

我正在创建名为“stream:stream”的 XElement 对象,但它引发了 XMLException 这样':' 不能包含在名称中。

这里的第一个流是一个命名空间。

最佳答案

您可以像这样指定命名空间:

XNamespace streamNs = "some-url-here";
// The + operator here creates an XName
XElement element = new XElement(streamNs + "stream");

要创建一个“stream:stream”元素,您需要在某些元素中为 stream 添加一个 xmlns 属性,例如

// Add this to an element - either the element in the namespace, or some parent
// element. The document root is a common place to put all namespaces...
XAttribute streamNs = new XAttribute(XNamespace.Xmlns + "stream",
streamNs.NamespaceName);

关于c# - XElement 中的 XML 解析 ':',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8712667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com