David Thielen
David Thielen

Reputation: 33026

XmlElement.Attributes is dropping namespaces

If you prefer as a fiddle - click here.

In my debugger, I have an XmlElement.OuterXml of:

<?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" 

Note it's mc:Ignorable, not Ignorable.

I call XmlElement.Attributes and one of the attributes is for Ignorable but... enter image description here

It's lost the prefix/namespace.

Any idea what is going on here?

Update: I also posted on MSDN as the answer here so far is it's a bug and I'm surprised something so basic would be wrong.

Upvotes: 1

Views: 131

Answers (1)

Pavan Chandaka
Pavan Chandaka

Reputation: 12821

You may not get it directly as a part of name of the attribute. There is a property "Prefix" , which is expected to return but it is empty. But GetPrefixOfNamespace is returning the prefix properly after passing the attribute's namespace URI as input. Could be some implementation issue. So for now try as said below.

var list = inner.Attributes;
foreach (System.Xml.XmlAttribute attr in list)
    Console.WriteLine(attr.GetPrefixOfNamespace(attr.NamespaceURI) + ":" + attr.Name);

Upvotes: 2

Related Questions