ReasonCodeExample.XPathInformation.Writers.XPathWriter.WriteAttributeName C# (CSharp) Method

WriteAttributeName() private method

private WriteAttributeName ( System.Xml.Linq.XAttribute attribute ) : void
attribute System.Xml.Linq.XAttribute
return void
        private void WriteAttributeName(XAttribute attribute)
        {
            XPath.Append("@");
            if(string.IsNullOrEmpty(attribute.Name.NamespaceName))
            {
                XPath.Append(attribute.Name.LocalName);
                return;
            }

            if(attribute.Parent == null)
            {
                throw new XmlException($"Unable to determine namespace prefix for attribute \"{attribute.Name}\". Parent is null.");
            }

            var namespacePrefix = attribute.Parent.GetPrefixOfNamespace(attribute.Name.Namespace);
            if(string.IsNullOrEmpty(namespacePrefix))
            {
                WriteAttributeNameWithoutPrefix(attribute.Name);
            }
            else
            {
                WriteAttributeNameWithPrefix(namespacePrefix, attribute.Name.LocalName);
            }
        }