System.Xml.XmlDocument.CreateAttribute C# (CSharp) Method

CreateAttribute() public method

public CreateAttribute ( String name ) : XmlAttribute
name String
return XmlAttribute
        public XmlAttribute CreateAttribute(String name)
        {
            String prefix = String.Empty;
            String localName = String.Empty;
            String namespaceURI = String.Empty;

            SplitName(name, out prefix, out localName);

            SetDefaultNamespace(prefix, localName, ref namespaceURI);

            return CreateAttribute(prefix, localName, namespaceURI);
        }

Same methods

XmlDocument::CreateAttribute ( String qualifiedName, String namespaceURI ) : XmlAttribute
XmlDocument::CreateAttribute ( string prefix, string localName, string namespaceURI ) : XmlAttribute

Usage Example

    //
    //  METHOD      : BuildDetail
    //  DESCRIPTION : Create bulk of error log, parameters fill in the specific details like error type, variable name, and explanation
    //  PARAMETERS  : string name                 - Variable name
    //                string type                 - Error type
    //                string explanation          - Explanation of error
    //  RETURNS     : XmlNode node                - XML containing constructed log.
    //
    public XmlNode BuildDetail(string name, string type, string explanation)
    {
        XmlDocument  doc  = new System.Xml.XmlDocument();
        XmlNode      node = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
        XmlNode      details;
        XmlAttribute nameAttr;
        XmlAttribute errorTypeAttr;
        XmlAttribute explanationAttr;

        details               = doc.CreateNode(XmlNodeType.Element, "ParameterError", "http://localhost/LoanService");
        nameAttr              = doc.CreateAttribute("s", "name", "http://localhost/LoanService");
        nameAttr.Value        = name;
        errorTypeAttr         = doc.CreateAttribute("s", "errorType", "http://localhost/LoanService");
        errorTypeAttr.Value   = type;
        explanationAttr       = doc.CreateAttribute("s", "explanation", "http://localhost/LoanService");
        explanationAttr.Value = explanation;

        details.Attributes.Append(nameAttr);
        details.Attributes.Append(errorTypeAttr);
        details.Attributes.Append(explanationAttr);

        node.AppendChild(details);

        return(node);
    }
All Usage Examples Of System.Xml.XmlDocument::CreateAttribute