• Stars
    star
    44
  • Rank 634,578 (Top 13 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

XML DOM processing for Golang, supports xpath query

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

More Repositories

1

jetbrick-template-2x

Template Engine for Java
Java
371
star
2

frep

Generate file using template from environment, arguments, json/yaml/toml config files
Go
154
star
3

javadoc.chm

This software generates an Microsoft HTML Help(CHM) from generic javadoc style API documents
Java
143
star
4

angular-async-loader

Load modules and components asynchronously for angular 1.x application.
JavaScript
136
star
5

jetbrick-template-1x

Java template engine, quickly and easily.
Java
68
star
6

go-trylock

TryLock support on read-write lock for Golang
Go
33
star
7

jetbrick-webmvc

jetbrick web mvc framework
Java
25
star
8

centos-7-kickstart

build a centos 7 iso/ovf/ova with kickstart
Shell
21
star
9

jetbrick-commons

jetbrick utility classes
Java
21
star
10

go-log

Simple and configurable Logging in Go, with level, formatters and writers
Go
14
star
11

go-cli

A full-featured and easy to use command-line package
Go
13
star
12

jetbrick-template-2x-samples

Samples for jetbrick-template-2x
Java
11
star
13

jetbrick-template-1x-samples

The samples for jetbrick-template integrated with webmvc
Java
9
star
14

jetbrick-ioc

IoC framwork for jetbrick
Java
7
star
15

jetbrick-webmvc-samples

Samples for jetbrick-webmvc
Java
6
star
16

go-stack

Common utility functions for Golang
Go
6
star
17

go-tableify

Pretty console printing of tabular data
Go
5
star
18

go-curl

A Go HTTP client library for creating and sending API requests
Go
5
star
19

jetbrick-orm

Object-relational mapping framework
Java
4
star
20

jetbrick-all-1x

A full-stack framework written with java
Java
4
star
21

gls

A goroutine-local storage for golang
Go
3
star
22

subchen.github.io

WebSite for subchen.github.com
HTML
3
star
23

ovfenv-installer

Configure networking from vSphere ovfEnv properties
Go
3
star
24

homebrew-tap

Tools of macOS Homebrew Packages
Ruby
2
star
25

snack

Generic functional library for javascript/node.js
JavaScript
2
star
26

snack-string

Generic string functional library for javascript/node.js
JavaScript
2
star
27

dev-box

A development box deployer, Support macOS, CentOS and Ubuntu.
Shell
2
star
28

shaft

Java simple database operation framework
Java
2
star
29

snack-cli

command-line interfaces for node.js
JavaScript
2
star
30

bintray-cli

Command line for api.bintray.com
1
star
31

jetbrick-template-shiro

Shiro tag extension for jetbrick-template
Java
1
star
32

jetbrick-website-app

website for http://subchen.github.io/
Java
1
star
33

jetbrick-extension

jetbrick extension modules
Java
1
star
34

jetbrick-jdbclog

jdbc logger for jetbrick
Java
1
star
35

jetbrick-ioc-spring

Spring intergrate for Jetbrick IoC
Java
1
star