Popularity
3.7
Growing
Activity
1.1
-
47
3
29
Programming language: Go
License: Apache License 2.0
Latest version: v1.1.2
go-xmldom alternatives and similar packages
Based on the "XML" category.
Alternatively, view go-xmldom alternatives based on common mentions on social networks and blogs.
-
xmlwriter
xmlwriter is a pure-Go library providing procedural XML generation based on libxml2's xmlwriter module
CodeRabbit: AI Code Reviews for Developers
Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
Promo
coderabbit.ai
Do you think we are missing an alternative of go-xmldom or a related project?
Popular Comparisons
README
go-xmldom
XML DOM processing for Golang, supports xpath query
- Parse XML into dom
- Query node using xpath
- Update XML using dom
Installation
$ go get github.com/subchen/go-xmldom
Basic Usage
xml := `<testsuite tests="2" failures="0" time="0.009" name="github.com/subchen/go-xmldom">
<testcase classname="go-xmldom" name="ExampleParseXML" time="0.004"></testcase>
<testcase classname="go-xmldom" name="ExampleParse" time="0.005"></testcase>
</testsuite>`
doc := xmldom.Must(xmldom.ParseXML(xml))
root := doc.Root
name := root.GetAttributeValue("name")
time := root.GetAttributeValue("time")
fmt.Printf("testsuite: name=%v, time=%v\n", name, time)
for _, node := range root.GetChildren("testcase") {
name := node.GetAttributeValue("name")
time := node.GetAttributeValue("time")
fmt.Printf("testcase: name=%v, time=%v\n", name, time)
}
Xpath Query
// find all children
fmt.Printf("children = %v\n", len(node.Query("//*")))
// find node matched tag name
nodeList := node.Query("//testcase")
for _, c := range nodeList {
fmt.Printf("%v: name = %v\n", c.Name, c.GetAttributeValue("name"))
}
// find node matched attr name
c := node.QueryOne("//testcase[@name='ExampleParseXML']")
fmt.Printf("%v: name = %v\n", c.Name, c.GetAttributeValue("name"))
Create XML
doc := xmldom.NewDocument("testsuites")
suiteNode := doc.Root.CreateNode("testsuite").SetAttributeValue("name", "github.com/subchen/go-xmldom")
suiteNode.CreateNode("testcase").SetAttributeValue("name", "case 1")
suiteNode.CreateNode("testcase").SetAttributeValue("name", "case 2")
fmt.Println(doc.XML())
License
go-xmldom
is released under the Apache 2.0 license. See LICENSE
*Note that all licence references and agreements mentioned in the go-xmldom README section above
are relevant to that project's source code only.