本文整理匯總了Golang中github.com/lestrrat/go-libxml2/types.Document.CreateElementNS方法的典型用法代碼示例。如果您正苦於以下問題:Golang Document.CreateElementNS方法的具體用法?Golang Document.CreateElementNS怎麽用?Golang Document.CreateElementNS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lestrrat/go-libxml2/types.Document
的用法示例。
在下文中一共展示了Document.CreateElementNS方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MakeXMLNode
func (key *RSA) MakeXMLNode(doc types.Document) (types.Node, error) {
var root types.Node
var err error
prefix, err := doc.LookupNamespacePrefix(xmlsec.DSigNs)
if err != nil {
// namespace does not exist. make me a namespace
root, err = doc.CreateElementNS(xmlsec.DSigNs, xmlsec.Prefix+":KeyInfo")
if err != nil {
return nil, err
}
prefix = xmlsec.Prefix
} else {
root, err = doc.CreateElement(prefix + ":KeyInfo")
if err != nil {
return nil, err
}
}
defer root.AutoFree()
root.MakeMortal()
kvnode, err := doc.CreateElement(prefix + ":KeyValue")
if err != nil {
return nil, err
}
root.AddChild(kvnode)
rsakeynode, err := doc.CreateElement(prefix + ":RSAKeyValue")
if err != nil {
return nil, err
}
kvnode.AddChild(rsakeynode)
mnode, err := doc.CreateElement(prefix + ":Modulus")
if err != nil {
return nil, err
}
mnode.AppendText(base64.StdEncoding.EncodeToString(key.key.N.Bytes()))
rsakeynode.AddChild(mnode)
enode, err := doc.CreateElement(prefix + ":Exponent")
if err != nil {
return nil, err
}
data := make([]byte, 8)
binary.BigEndian.PutUint64(data, uint64(key.key.E))
i := 0
for ; i < len(data); i++ {
if data[i] != 0x0 {
break
}
}
enode.AppendText(base64.StdEncoding.EncodeToString(data[i:]))
rsakeynode.AddChild(enode)
root.MakePersistent()
return root, nil
}
示例2: MakeXMLNode
func (a Assertion) MakeXMLNode(d types.Document) (types.Node, error) {
axml, err := d.CreateElementNS(ns.SAML.URI, ns.SAML.AddPrefix("Assertion"))
if err != nil {
return nil, err
}
axml.SetNamespace(ns.XMLSchema.URI, ns.XMLSchema.Prefix, false)
axml.SetNamespace(ns.XMLSchemaInstance.URI, ns.XMLSchemaInstance.Prefix, false)
axml.SetAttribute("ID", a.ID)
axml.SetAttribute("Version", a.Version)
axml.SetAttribute("IssueInstant", a.IssueInstant.Format(TimeFormat))
iss, err := d.CreateElementNS(ns.SAML.URI, ns.SAML.AddPrefix("Issuer"))
if err != nil {
return nil, err
}
iss.AppendText(a.Issuer)
axml.AddChild(iss)
for _, noder := range []MakeXMLNoder{a.Subject, a.Conditions, a.AuthnStatement, a.AttributeStatement} {
n, err := noder.MakeXMLNode(d)
if err != nil {
return nil, err
}
axml.AddChild(n)
}
return axml, nil
}
示例3: MakeXMLNode
func (m Message) MakeXMLNode(d types.Document) (types.Node, error) {
mxml, err := d.CreateElement("Message")
if err != nil {
return nil, err
}
mxml.MakeMortal()
defer mxml.AutoFree()
mxml.SetAttribute("ID", m.ID)
mxml.SetAttribute("Version", m.Version)
mxml.SetAttribute("IssueInstant", m.IssueInstant.Format(TimeFormat))
if v := m.Destination; v != "" {
mxml.SetAttribute("Destination", v)
}
if v := m.Consent; v != "" {
mxml.SetAttribute("Consent", v)
}
// XXX Comeback later.
iss, err := d.CreateElementNS(ns.SAML.URI, ns.SAML.AddPrefix("Issuer"))
if err != nil {
return nil, err
}
iss.AppendText(m.Issuer)
mxml.AddChild(iss)
mxml.MakePersistent()
return mxml, nil
}
示例4: MakeXMLNode
func (desc IDPDescriptor) MakeXMLNode(doc types.Document) (types.Node, error) {
root, err := doc.CreateElementNS(ns.Metadata.URI, ns.Metadata.AddPrefix("EntityDescriptor"))
if err != nil {
return nil, err
}
defer root.AutoFree()
root.MakeMortal()
root.SetNamespace(ns.XMLDSignature.URI, ns.XMLDSignature.Prefix, false)
root.SetAttribute("entityID", desc.ID())
idpdesc, err := doc.CreateElement("md:IDPSSODescriptor")
if err != nil {
return nil, err
}
root.AddChild(idpdesc)
if len(desc.RoleDescriptor.ProtocolSupportEnumerations) == 0 {
desc.RoleDescriptor.ProtocolSupportEnumerations = []string{ns.SAMLP.URI}
}
protobuf := bytes.Buffer{}
for i, proto := range desc.RoleDescriptor.ProtocolSupportEnumerations {
protobuf.WriteString(proto)
if i != len(desc.RoleDescriptor.ProtocolSupportEnumerations)-1 {
protobuf.WriteString(" ")
}
}
idpdesc.SetAttribute("protocolSupportEnumeration", protobuf.String())
if k := desc.KeyDescriptor; k != nil {
kdesc, err := k.MakeXMLNode(doc)
if err != nil {
return nil, err
}
idpdesc.AddChild(kdesc)
}
if v := desc.ErrorURL; v != "" {
idpdesc.SetAttribute("errorURL", v)
}
for _, sls := range desc.SingleLogoutServices() {
sls.Name = "SingleLogoutService"
slsdesc, err := sls.MakeXMLNode(doc)
if err != nil {
return nil, err
}
idpdesc.AddChild(slsdesc)
}
{
nif, err := desc.NameIDFormat.MakeXMLNode(doc)
if err != nil {
return nil, err
}
idpdesc.AddChild(nif)
}
for _, ssos := range desc.SingleSignOnService {
ssos.Name = "SingleSignOnService"
ssosdesc, err := ssos.MakeXMLNode(doc)
if err != nil {
return nil, err
}
idpdesc.AddChild(ssosdesc)
}
if cp := desc.ContactPerson; cp != nil {
cpnode, err := cp.MakeXMLNode(doc)
if err != nil {
return nil, err
}
root.AddChild(cpnode)
}
root.MakePersistent()
return root, nil
}