带命名空间的xml生成

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生成)