All Projects → subchen → go-xmldom

subchen / go-xmldom

Licence: Apache-2.0 license
XML DOM processing for Golang, supports xpath query

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-xmldom

Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (+5002.63%)
Mutual labels:  dom, xpath, xml-parser
Pugixml
Light-weight, simple and fast XML parser for C++ with XPath support
Stars: ✭ 2,809 (+7292.11%)
Mutual labels:  dom, xpath, xml-parser
Xmlquery
xmlquery is Golang XPath package for XML query.
Stars: ✭ 209 (+450%)
Mutual labels:  xpath, xml-parser
fox
A Fortran XML library
Stars: ✭ 51 (+34.21%)
Mutual labels:  dom, xml-parser
Fluentdom
A fluent api for working with XML in PHP
Stars: ✭ 327 (+760.53%)
Mutual labels:  dom, xpath
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (+1052.63%)
Mutual labels:  xpath, xml-parser
ElementFinder
Fetch data from HTML and XML via xpath/css and prepare it with regexp
Stars: ✭ 29 (-23.68%)
Mutual labels:  dom, xpath
Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (+2252.63%)
Mutual labels:  xpath, xml-parser
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+24068.42%)
Mutual labels:  dom, xpath
Domquery
PHP library for easy 'jQuery like' DOM traversing and manipulation.
Stars: ✭ 84 (+121.05%)
Mutual labels:  dom, xpath
Jquery Xpath
jQuery XPath plugin (with full XPath 2.0 language support)
Stars: ✭ 173 (+355.26%)
Mutual labels:  dom, xpath
Xml
XML without worries
Stars: ✭ 35 (-7.89%)
Mutual labels:  dom, xpath
xpath2.js
xpath.js - Open source XPath 2.0 implementation in JavaScript (DOM agnostic)
Stars: ✭ 74 (+94.74%)
Mutual labels:  dom, xpath
exml
Most simple Elixir wrapper for xmerl xpath
Stars: ✭ 23 (-39.47%)
Mutual labels:  xpath, xml-parser
rottenjs
An all-in-one (2.6kb) Javascript library for web development
Stars: ✭ 15 (-60.53%)
Mutual labels:  dom
zebrajs
A modular, jQuery compatible, ultra light-weight JavaScript micro-library for modern browsers
Stars: ✭ 26 (-31.58%)
Mutual labels:  dom
foliage
🍃 Style your components with performance
Stars: ✭ 29 (-23.68%)
Mutual labels:  dom
react-append-to-body
React Higher order component that allows you to attach components to the DOM outside of the main app.
Stars: ✭ 30 (-21.05%)
Mutual labels:  dom
OpenScraper
An open source webapp for scraping: towards a public service for webscraping
Stars: ✭ 80 (+110.53%)
Mutual labels:  xpath
cheatsheets
📋 Various cheatsheets made while working as a developer
Stars: ✭ 22 (-42.11%)
Mutual labels:  dom

go-xmldom

Go Report Card GoDoc

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 the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].