美文网首页
带命名空间的xml生成

带命名空间的xml生成

作者: 价值投机168 | 来源:发表于2022-09-02 16:52 被阅读0次
    static void Main(string[] args)
    
        {
            string id = "_" + System.Guid.NewGuid().ToString();
            string issue_instant = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
            string issuer = "client";
    
            XNamespace samlp = "urn:oasis:names:tc:SAML:2.0:protocol";
            XNamespace saml = "urn:oasis:names:tc:SAML:2.0:assertion";
            XElement root = new XElement(samlp + "AuthnRequest",
                new XAttribute(XNamespace.Xmlns + "samlp", samlp.NamespaceName),
                new XAttribute(XNamespace.Xmlns + "saml", saml.NamespaceName),
                new XAttribute("ID", id),
                new XAttribute("Version", "2.0"),
                new XAttribute("IssueInstant", issue_instant),
                new XAttribute("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"),
    
            new XElement(saml + "Issuer",issuer),
    
                new XElement(samlp + "NameIDPolicy", new XAttribute("Format", "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"),
                new XAttribute("AllowCreate", "true"))
            );
            File.WriteAllText("test.xml", root.ToString());
            Console.WriteLine(root);
    
            Console.Read();
    
        }

    相关文章

      网友评论

          本文标题:带命名空间的xml生成

          本文链接:https://www.haomeiwen.com/subject/dxhynrtx.html