Comments (4)
Assuming an existing document, I tried to create a new document like this doc1 := xml.CreateEmptyDocument(doc.InputEncoding(), doc.OutputEncoding())
and then added a child thusly doc1.Root().AddChild(doc.Root().FirstChild())
.
This doesn't work because there's no root element on the new document.
from gokogiri.
This crashes and burns on that last doc1.Free()
. What am I doing wrong?
package main
import (
log "code.google.com/p/log4go"
g "github.com/moovweb/gokogiri"
"github.com/moovweb/gokogiri/xml"
//"strings"
"time"
)
var data = `
<body xmlns="http://jabber.org/protocol/httpbind" xmlns:stream="http://etherx.jabber.org/streams" to="127.0.0.1" rid="3" sid="0acad5262d995374">
<iq id="2" type="get" from="">
<query xmlns="jabber:iq:auth">
<username>xyz</username>
</query>
</iq>
</body>
`
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
doc, err := g.ParseXml([]byte(data))
if err != nil {
log.Error("ParseXml error: %v", err)
return
}
defer doc.Free()
root := doc.Root()
doc1 := xml.CreateEmptyDocument(doc.InputEncoding(), doc.OutputEncoding())
child := root.FirstChild().NextSibling().Duplicate(-1)
log.Debug("child = %s", child)
err = doc1.Node.AddChild(child)
log.Debug("err = %v", err)
log.Debug("doc1 = %s", doc1)
doc1.Free()
<-time.After(1 * time.Second)
}
from gokogiri.
Pull request #31 settles this issue.
from gokogiri.
Interesting, sorry we couldn't get to this in time, but thanks for taking the initiative to provide a fix =)
from gokogiri.
Related Issues (20)
- identifier "_Ctype_struct__xmlDoc" may conflict with identifiers generated by cgo HOT 4
- Get error when start Docker container
- WIndows installation
- Encoding is passed around as byte array instead of string HOT 5
- performance issue of XmlNode.SetContent() HOT 1
- strange behavior in href attribute, uri with parameters HOT 2
- How do I parse xml with a namespace? HOT 2
- XSD Validation? HOT 1
- Issues with go get github.com/moovweb/gokogiri/css HOT 2
- Attempting to cross compile for linux/amd64 on OSX fails using gox HOT 1
- Trim surrounding whitespace for Node.Content() HOT 2
- How to get arttr with CSS HOT 2
- El capitan issue HOT 1
- Crash with custom XPath resolver HOT 3
- Parsing XML dies (stays blocked) when doing in parallel HOT 2
- Go1.6 compatibility HOT 2
- Go 1.6: runtime error: cgo argument has Go pointer to Go pointer HOT 6
- Save DOM model as xml file
- build constraints exclude all Go files in /moovweb/gokogiri/help, failed to build with arch=386 HOT 1
- pkg-config: exec: "pkg-config": executable file not found in %PATH%
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gokogiri.