本文整理汇总了Golang中github.com/lestrrat/go-libxml2/types.Document.CreateElement方法的典型用法代码示例。如果您正苦于以下问题:Golang Document.CreateElement方法的具体用法?Golang Document.CreateElement怎么用?Golang Document.CreateElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lestrrat/go-libxml2/types.Document
的用法示例。
在下文中一共展示了Document.CreateElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MakeXMLNode
func (sc SubjectConfirmation) MakeXMLNode(d types.Document) (types.Node, error) {
scxml, err := d.CreateElement(ns.SAML.AddPrefix("SubjectConfirmation"))
if err != nil {
return nil, err
}
scxml.MakeMortal()
defer scxml.AutoFree()
method := sc.Method
if sc.Method == "" {
method = Bearer
}
scxml.SetAttribute("Method", method.String())
scd, err := d.CreateElement(ns.SAML.AddPrefix("SubjectConfirmationData"))
if err != nil {
return nil, err
}
scd.SetAttribute("InResponseTo", sc.InResponseTo)
scd.SetAttribute("Recipient", sc.Recipient)
scd.SetAttribute("NotOnOrAfter", sc.NotOnOrAfter.Format(TimeFormat))
scxml.AddChild(scd)
scxml.MakePersistent()
return scxml, nil
}
示例2: 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
}
示例3: 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
}
示例4: MakeXMLNode
func (nif Format) MakeXMLNode(doc types.Document) (types.Node, error) {
root, err := doc.CreateElement("md:NameIDFormat")
if err != nil {
return nil, err
}
root.AppendText(Transient)
return root, nil
}
示例5: MakeXMLNode
func (res Response) MakeXMLNode(d types.Document) (types.Node, error) {
oresxml, err := res.Message.MakeXMLNode(d)
if err != nil {
return nil, err
}
resxml := oresxml.(types.Element)
resxml.MakeMortal()
defer resxml.AutoFree()
resxml.SetNodeName("Response")
resxml.SetNamespace(ns.SAMLP.URI, ns.SAMLP.Prefix, true)
resxml.SetNamespace(ns.SAML.URI, ns.SAML.Prefix, false)
if v := res.InResponseTo; v != "" {
resxml.SetAttribute("InResponseTo", v)
}
st, err := d.CreateElement("samlp:Status")
if err != nil {
return nil, err
}
stc, err := d.CreateElement("samlp:StatusCode")
if err != nil {
return nil, err
}
stc.SetAttribute("Value", res.Status.String())
st.AddChild(stc)
resxml.AddChild(st)
if assertion := res.Assertion; assertion != nil {
axml, err := assertion.MakeXMLNode(d)
if err != nil {
return nil, err
}
resxml.AddChild(axml)
}
resxml.MakePersistent()
return resxml, nil
}
示例6: MakeXMLNode
func (kd KeyDescriptor) MakeXMLNode(doc types.Document) (types.Node, error) {
kdnode, err := doc.CreateElement("md:KeyDescriptor")
if err != nil {
return nil, err
}
defer kdnode.AutoFree()
kdnode.MakeMortal()
if v := kd.Use; v != "" {
kdnode.SetAttribute("use", v)
}
keynode, err := kd.Key.MakeXMLNode(doc)
if err != nil {
return nil, err
}
kdnode.AddChild(keynode)
kdnode.MakePersistent()
return kdnode, nil
}