c# - XmlElement.Attributes 正在删除命名空间
问题描述
如果您喜欢小提琴,请单击此处。
在我的调试器中,我有一个 XmlElement.OuterXml:
<?xml version="1.0"?>
<p:sld mc:Ignorable="p14 a14 p15 p16 a16 thm15 adec ahyp v"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:asvg="http://schemas.microsoft.com/office/drawing/2016/SVG/main"
xmlns:ahyp="http://schemas.microsoft.com/office/drawing/2018/hyperlinkcolor"
xmlns:adec="http://schemas.microsoft.com/office/drawing/2017/decorative"
xmlns:thm15="http://schemas.microsoft.com/office/thememl/2012/main"
xmlns:p16="http://schemas.microsoft.com/office/powerpoint/2015/main"
xmlns:p15="http://schemas.microsoft.com/office/powerpoint/2012/main"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:a16="http://schemas.microsoft.com/office/drawing/2014/main"
请注意,它是 mc:Ignorable,而不是 Ignorable。
我调用 XmlElement.Attributes 并且其中一个属性是 Ignorable 但是......
它丢失了前缀/命名空间。
知道这里发生了什么吗?
更新:我还在 MSDN 上发布了到目前为止的答案是这是一个错误,我很惊讶这么基本的东西会出错。
解决方案
您可能无法直接将其作为属性名称的一部分。有一个属性 "Prefix" ,预计会返回,但它是空的。但是GetPrefixOfNamespace
在将属性的命名空间 URI 作为输入传递后正确返回前缀。可能是一些实施问题。所以现在尝试如下所述。
var list = inner.Attributes;
foreach (System.Xml.XmlAttribute attr in list)
Console.WriteLine(attr.GetPrefixOfNamespace(attr.NamespaceURI) + ":" + attr.Name);
推荐阅读
- excel - 尝试创建数据透视表,运行时错误 91
- html - 使组件添加新组件的问题
- swift - didRequestRegionState 在 iOS 13 上失败
- excel - 通过excel vba创建表格并将数据放入word中显示错误
- reactjs - 如何在进行单元测试时调用 React 组件的自定义方法。我正在使用打字稿
- c++ - 使用 glutBitmapCharacter() 绘制文本关闭 opengl 程序
- android - 下载完成带下划线的复选标记在哪里
- agda - 如何处理冲突的模块定义?
- php - 如何使不同形式的按钮彼此相邻?
- python - JavaScript 适用于 chrome 控制台,但不适用于 firefox 或 selenium 代码