本文整理汇总了Golang中github.com/jteeuwen/go-pkg-xmlx.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: verifyDocs
func verifyDocs(origData, faksData []byte) (errs []error) {
orig, faks := xmlx.New(), xmlx.New()
err := orig.LoadBytes(origData, nil)
if err == nil {
if err = faks.LoadBytes(faksData, nil); err == nil {
errs = verifyNode(orig.Root, faks.Root)
}
}
return
}
示例2: getRoster
func getRoster(msg string) (map[string]*Contact, os.Error) {
contactMap := make(map[string]*Contact)
xmlDoc := xmlx.New()
if err := xmlDoc.LoadString(msg); err != nil {
logError(err)
return nil, err
}
/*
<iq to='[email protected]/balcony' type='result' id='roster_1'>
<query xmlns='jabber:iq:roster'>
<item jid='[email protected]'
name='Romeo'
subscription='both'>
<group>Friends</group>
</item>
</query>
</iq>
*/
nodes := xmlDoc.SelectNodes("jabber:iq:roster", "item")
for _, node := range nodes {
tempContact := new(Contact)
tempContact.Name = node.GetAttr("", "name")
tempContact.Subscription = node.GetAttr("", "subscription")
tempContact.JID = node.GetAttr("", "jid")
tempContact.Show = "offline"
tempContact.Status = ""
contactMap[tempContact.JID] = tempContact
}
return contactMap, nil
}
示例3: Success
func (cb *CnBeta) Success(buf []byte) {
doc := xmlx.New()
if err := doc.LoadBytes(buf, nil); err != nil {
cb.Failure(err)
return
}
cb.listener.OnSuccess(parser(doc))
cb.listener.OnEnd()
}
示例4: FetchBytes
// Fetch retrieves the feed's content from the []byte
//
// The charset parameter overrides the xml decoder's CharsetReader.
// This allows us to specify a custom character encoding conversion
// routine when dealing with non-utf8 input. Supply 'nil' to use the
// default from Go's xml package.
func (this *Feed) FetchBytes(uri string, content []byte, charset xmlx.CharsetFunc) (err error) {
this.Url = uri
doc := xmlx.New()
if err = doc.LoadBytes(content, charset); err != nil {
return
}
return this.makeFeed(doc)
}
示例5: FetchClient
// Fetch retrieves the feed's latest content if necessary.
//
// The charset parameter overrides the xml decoder's CharsetReader.
// This allows us to specify a custom character encoding conversion
// routine when dealing with non-utf8 input. Supply 'nil' to use the
// default from Go's xml package.
//
// The client parameter allows the use of arbitrary network connections, for
// example the Google App Engine "URL Fetch" service.
func (this *Feed) FetchClient(uri string, client *http.Client, charset xmlx.CharsetFunc) (err error) {
if !this.CanUpdate() {
return
}
this.Url = uri
doc := xmlx.New()
if err = doc.LoadUriClient(uri, client, charset); err != nil {
return
}
return this.makeFeed(doc)
}
示例6: main
func main() {
doc := xmlx.New()
err := doc.LoadUri("https://github.com/sbhackerspace/" + "sbhx-snippets" + "/commits/master.atom")
if err != nil {
fmt.Printf("Error: %v\n", err)
} else {
children := doc.SelectNode("", "").Children
fmt.Printf("Num children: %v\n", len(children))
for i, child := range children {
fmt.Printf("Child %v: %v\n", i, child.Children)
fmt.Printf("\n\n")
}
}
}
示例7: Parse
func Parse(r io.Reader, charset xmlx.CharsetFunc) (chs []*Channel, err error) {
doc := xmlx.New()
if err = doc.LoadStream(r, charset); err != nil {
return
}
format, version := GetVersionInfo(doc)
if ok := testVersions(format, version); !ok {
err = errors.New(fmt.Sprintf("Unsupported feed: %s, version: %+v", format, version))
return
}
return buildFeed(format, doc)
}
示例8: getFeatures
/**
* For each feature type, return a slice of values
*/
func getFeatures(msg string) (map[string][]string, os.Error) {
keyValueMap := make(map[string][]string)
xmlDoc := xmlx.New()
if err := xmlDoc.LoadString(msg); err != nil {
logError(err)
return nil, err
}
/*
<stream:features>
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>DIGEST-MD5</mechanism>
<mechanism>PLAIN</mechanism>
</mechanisms>
</stream:features>
*/
nodes := xmlDoc.SelectNodes(nsSASL, "mechanism")
for _, node := range nodes {
keyValueMap["mechanism"] = append(keyValueMap["mechanism"], node.Value)
logVerbose("mechanism: %s", node.Value)
}
/*
stream:features>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
</stream:features>
*/
nodes = xmlDoc.SelectNodes(nsBind, "bind")
for _, node := range nodes {
keyValueMap["bind"] = append(keyValueMap["bind"], node.Value)
logVerbose("bind: %s", node.Value)
}
/*
stream:features>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</stream:features>
*/
nodes = xmlDoc.SelectNodes(nsSession, "session")
for _, node := range nodes {
keyValueMap["session"] = append(keyValueMap["session"], node.Value)
logVerbose("session: %s", node.Value)
}
return keyValueMap, nil
}
示例9: Export
func Export(object export.Exportable) error {
outFile := fmt.Sprintf("%v.dae", object.GetName())
ctx := Context{
Object: xmlx.New(),
imageIds: make(map[string]string),
}
ctx.Object.Root = xmlx.NewNode(xmlx.NT_ROOT)
root := ctx.Object.Root
collada := addChild(root, "COLLADA",
Attribs{"xmlns": "http://www.collada.org/2005/11/COLLADASchema", "version": "1.4.1"}, "")
asset := addChild(collada, "asset", nil, "")
_ = addChild(asset, "unit", Attribs{"meter": "1", "name": "meter"}, "")
_ = addChild(asset, "up_axis", nil, "Y_UP")
ctx.libImages = addChild(collada, "library_images", nil, "")
ctx.libMaterials = addChild(collada, "library_materials", nil, "")
ctx.libEffects = addChild(collada, "library_effects", nil, "")
ctx.libGeometries = addChild(collada, "library_geometries", nil, "")
ctx.libScenes = addChild(collada, "library_visual_scenes", nil, "")
ctx.scene = addChild(ctx.libScenes, "visual_scene", Attribs{"id": "Scene",
"name": object.GetName()}, "")
scenes := addChild(collada, "scene", nil, "")
_ = addChild(scenes, "instance_visual_scene", Attribs{"url": "#Scene"}, "")
for _, model := range object.GetModels() {
var err error
if err = ExportMaterials(&ctx, model); err != nil {
return err
}
if err = ExportGeometries(&ctx, model); err != nil {
return err
}
}
if err := ctx.Object.SaveFile(outFile); err != nil {
return err
}
return nil
}
示例10: FetchClient
// Fetch retrieves the feed's latest content if necessary.
//
// The charset parameter overrides the xml decoder's CharsetReader.
// This allows us to specify a custom character encoding conversion
// routine when dealing with non-utf8 input. Supply 'nil' to use the
// default from Go's xml package.
//
// The client parameter allows the use of arbitrary network connections, for
// example the Google App Engine "URL Fetch" service.
func (this *Feed) FetchClient(uri string, client *http.Client, charset xmlx.CharsetFunc) (err error) {
if !this.CanUpdate() {
return
}
this.lastupdate = time.Now().UTC()
this.Url = uri
doc := xmlx.New()
if err = doc.LoadUriClient(uri, client, charset); err != nil {
return
}
if err = this.makeFeed(doc); err == nil {
// Only if fetching and parsing succeeded.
this.ignoreCacheOnce = false
}
return
}
示例11: Fetch
// Fetch retrieves the feed's latest content if necessary.
//
// The charset parameter overrides the xml decoder's CharsetReader.
// This allows us to specify a custom character encoding conversion
// routine when dealing with non-utf8 input. Supply 'nil' to use the
// default from Go's xml package.
func (this *Feed) Fetch(uri string, charset xmlx.CharsetFunc) (err error) {
if !this.CanUpdate() {
return
}
this.Url = uri
// Extract type and version of the feed so we can have the appropriate
// function parse it (rss 0.91, rss 0.92, rss 2, atom etc).
doc := xmlx.New()
if err = doc.LoadUri(uri, charset); err != nil {
return
}
this.Type, this.Version = this.GetVersionInfo(doc)
if ok := this.testVersions(); !ok {
err = errors.New(fmt.Sprintf("Unsupported feed: %s, version: %+v", this.Type, this.Version))
return
}
chancount := len(this.Channels)
if err = this.buildFeed(doc); err != nil || len(this.Channels) == 0 {
return
}
// Notify host of new channels
if chancount != len(this.Channels) && this.chanhandler != nil {
this.chanhandler(this, this.Channels[chancount:])
}
// reset cache timeout values according to feed specified values (TTL)
if this.EnforceCacheLimit && this.CacheTimeout < this.Channels[0].TTL {
this.CacheTimeout = this.Channels[0].TTL
}
return
}
示例12: getMessage
func getMessage(msg string) (MessageUpdate, os.Error) {
var tempMessage MessageUpdate
xmlDoc := xmlx.New()
if err := xmlDoc.LoadString(msg); err != nil {
logError(err)
return tempMessage, err
}
/*
<message
to='[email protected]/orchard'
from='[email protected]/balcony'
type='chat'
xml:lang='en'>
<body>Art thou not Romeo, and a Montague?</body>
<thread>e0ffe42b28561960c6b12b944a092794b9683a38</thread>
</message>
*/
node := xmlDoc.SelectNode("", "message")
if node != nil {
tempMessage.JID = node.GetAttr("", "from")
tempMessage.Type = node.GetAttr("", "type")
tempMessage.Body = node.GetValue("", "body")
node = xmlDoc.SelectNode(nsChatstates, "composing")
if node != nil {
tempMessage.State = "composing"
} else {
node = xmlDoc.SelectNode(nsChatstates, "active")
if node != nil {
tempMessage.State = "active"
}
}
}
return tempMessage, nil
}
示例13: main
func main() {
repo_names := []string{"sbhx-snippets", "sbhx-ircbot", "sbhx-rov",
"sbhx-sicp"} //, "sbhx-androidapp", "sbhx-projecteuler"
for _, repo := range repo_names[:1] {
result, err := ioutil.ReadFile(repo)
//defer ioutil.CloseFile(repo) // method doesn't exist
if err != nil {
fmt.Printf("%v\n", err)
} else {
//
// Parse XML
//
doc := xmlx.New()
if err = doc.LoadFile(string(result)); err != nil {
fmt.Printf("Error: %v\n", err)
} else {
fmt.Printf("Root:\n")
_ = doc.SelectNode("", "TreeRoot")
_ = doc.SelectNodes("", "item")
}
}
}
}
示例14: getPresenceUpdates
func getPresenceUpdates(msg string) ([]PresenceUpdate, os.Error) {
var updates []PresenceUpdate
var tempUpdate PresenceUpdate
xmlDoc := xmlx.New()
if err := xmlDoc.LoadString(msg); err != nil {
logError(err)
return nil, err
}
/*
<presence from='[email protected]/balcony' to='[email protected]/orchard' xml:lang='en'>
<show>away</show>
<status>be right back</status>
<priority>0</priority>
<x xmlns="vcard-temp:x:update">
<photo>8668b9b00eeb2e3a51ea5758e7cff9f7c5780309</photo>
</x>
</presence>
*/
nodes := xmlDoc.SelectNodes("", "presence")
for _, node := range nodes {
//sometimes jid in presence update comes with /resource, split it off
tempUpdate.JID = (strings.Split(node.GetAttr("", "from"), "/", -1))[0]
tempUpdate.Type = node.GetAttr("", "type")
tempUpdate.Show = node.GetValue("", "show")
tempUpdate.Status = node.GetValue("", "status")
//photo present? http://xmpp.org/extensions/xep-0153.html
if tempnode := node.SelectNode(nsVcardUpdate, "x"); tempnode != nil {
tempUpdate.PhotoHash = tempnode.GetValue(nsVcardUpdate, "photo")
logVerbose("PhotoHash In Presence Update: %s", tempUpdate.PhotoHash)
}
updates = append(updates, tempUpdate)
}
return updates, nil
}
示例15: main
func main() {
//
// Parse XML
//
doc := xmlx.New()
if err := doc.LoadFile("note.xml"); err != nil {
fmt.Printf("Error: %v\n", err)
} else {
notes := doc.SelectNodes("", "note")
for i, note := range notes {
if note != nil {
fmt.Printf("Note #%v: %v\n", i, note)
}
}
fmt.Printf("\n")
from := doc.SelectNodes("", "from")
to := doc.SelectNodes("", "to")
bodies := doc.SelectNodes("", "body")
for i, _ := range bodies {
fmt.Printf("From %v to %v: %v\n", from[i], to[i], bodies[i])
}
}
}