New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/qiuchengxuan/xml-builder

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/qiuchengxuan/xml-builder

  • v0.1.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

XML builder for Golang

xml-builder is a metaprogramming approach to build XML document like lxml in Python.

Creating a XML document

The following example creates an XML document from scratch using the xml-builder package and outputs its indented contents to stdout.

e := Tags(struct{ person, gender, firstname, lastname Tag }{})
doc := Doc(e.person(
	e.gender("female"),
	e.firstname("Anna"),
	e.lastname("Smith"),
))
bytes, _ := xml.MarshalIndent(doc, "", "    ")
fmt.Println(string(bytes))

Will output:

<person>
  <gender>female</gender>
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>

Attributes

This example illustrates how to define attributes in element

e := Tags(struct{ person, gender Tag }{})
doc := Doc(e.person(
	e.gender("female", Attrs{"a": "b", "xmlns:c": "xml.builder"}),
))
bytes, _ := xml.MarshalIndent(doc, "", "    ")
fmt.Println(string(bytes))

Will output:

<person>
  <gender a="b" xmlns:c="xml.builder">female</gender>
</person>

InstantElement

When unable to define tags, you can create as instant element as following:

person := E("person")
gender := E("gender", "female")
person.Append(gender)

Hook

When element name is snakecase or kebabcase, assuming you already had a function named snakecase, you can add a hook when creating tags as following:

e := Tags(struct{ firstName, lastName Tag }{}, func(name *xml.Name) {
	name.Local = snakecase(name.Local)
})

FAQs

Package last updated on 20 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc