Git Product home page Git Product logo

checkxml's Introduction

Package checkxml provides functions for validating XML data against a struct definition.

The MissingXMLTags functions decode XML data and return a slice of struct fields that will not be set using the encoding/xml Unmarshal function. The UnknownXMLTags functions decode XML data and return a slice of XML elements that will not be decoded using the encoding/xml Unmarshal function for the specified struct definition.

Example:

data := `<doc>
           <elem1>a simple element</elem1>
           <elem2>
             <subelem>something more complex</subelem>
             <notes>take a look at this</notes>
           </elem2>
           <elem4>extraneous</elem4>
         </doc>`

type sub struct {
	Subelem string `xml:"subelem,omitempty"`
	Another string `xml:"another"`
}
type elem struct {
	Elem1 string `xml:"elem1"`
	Elem2 sub    `xml:"elem2"`
	Elem3 bool   `xml:"elem3"`
}

e := new(elem)
result, root, _ := MissingXMLTags([]byte(data), e)
// result: [elem2.another elem3]
// root: doc

result, root, _ = UnknownXMLTags([]byte(data), e)
// result: [elem2.notes elem4]
// root: doc

NOTE: this package is dependent upon clbanning/mxj.

USAGE

https://godoc.org/github.com/clbanning/checkxml

MOTIVATION

I was having a conversation and the topic of validating streams of XML data from various sources came up. What the developer was looking for was a "signature" that could be used to route the data for refactoring to meet the production application requirements. Having already done something similar for JSON with the checkjson package and having the mxj package available, it was a simple exercise to do a mashup of the two packages.

RELATED

There is a complementary package for checking JSON objects against structs at https://github.com/clbanning/checkjson.

checkxml's People

Contributors

clbanning avatar sunsun314 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.