Beispiel #1
0
func main() {

	parseTree := xmltree.MustParseXML(os.Stdin, func(s *xmltree.ParseOptions) {
		s.Strict = false
	})
	goxpath.Marshal(parseTree, os.Stdout)
}
Beispiel #2
0
func main() {
	// no first command line arguments
	if len(os.Args) <= 1 {
		println("Usage:\r\n input.xml")
	}

	urlBasename := goxpath.MustParse(`basename(../@Url)`)
	transTimer := goxpath.MustParse(`ancestor::ms:TransactionTimer/@Name`)

	f, err := os.Open(os.Args[1])

	if err != nil {
		panic(err)
	}

	parseTree := xmltree.MustParseXML(f)
	reportingNames, err := goxpath.MustParse(`//ms:Request/@ReportingName`).ExecNode(parseTree, register)

	if err != nil {
		panic(err)
	}

	for _, i := range reportingNames {
		attr := i.(xmlnode.XMLNode)
		val := attr.Token.(*xml.Attr)

		val.Value = transTimer.MustExec(attr, register).String() + " - " +
			urlBasename.MustExec(attr, register).String()
	}

	goxpath.Marshal(parseTree, os.Stdout)
}
Beispiel #3
0
// getElementText will process the node to extract the elementName's text out of it (only first one found)
// returns utils.ErrNotFound if the element is not found in the node
func elementText(xmlRes tree.Res, elmntPath string) (string, error) {
	xp, err := goxpath.Parse(elmntPath)
	if err != nil {
		return "", err
	}
	elmntBuf := bytes.NewBufferString(xml.Header)
	if err := goxpath.Marshal(xmlRes.(tree.Node), elmntBuf); err != nil {
		return "", err
	}
	elmntNode, err := xmltree.ParseXML(elmntBuf)
	if err != nil {
		return "", err
	}
	elmnts, err := goxpath.Exec(xp, elmntNode, nil)
	if err != nil {
		return "", err
	}
	if len(elmnts) == 0 {
		return "", utils.ErrNotFound
	}
	return elmnts[0].String(), nil
}