コード例 #1
0
ファイル: gxp_Edit.go プロジェクト: suntong/lang
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)
}
コード例 #2
0
ファイル: xml_test.go プロジェクト: eloycoto/cgrates
func TestXMLHandlerSubstractUsage(t *testing.T) {
	xp := goxpath.MustParse(path.Join("/broadWorksCDR/cdrData/"))
	xmlTree := xmltree.MustParseXML(bytes.NewBufferString(cdrXmlBroadsoft), optsNotStrict)
	cdrs := goxpath.MustExec(xp, xmlTree, nil)
	cdrWithUsage := cdrs[1]
	if usage, err := handlerSubstractUsage(cdrWithUsage, utils.ParseRSRFieldsMustCompile("broadWorksCDR>cdrData>basicModule>releaseTime;^|;broadWorksCDR>cdrData>basicModule>answerTime", utils.INFIELD_SEP),
		utils.HierarchyPath([]string{"broadWorksCDR", "cdrData"}), "UTC"); err != nil {
		t.Error(err)
	} else if usage != time.Duration(13483000000) {
		t.Errorf("Expected: 13.483s, received: %v", usage)
	}
}
コード例 #3
0
ファイル: xml_test.go プロジェクト: eloycoto/cgrates
func TestXMLElementText(t *testing.T) {
	xp := goxpath.MustParse(path.Join("/broadWorksCDR/cdrData/"))
	xmlTree := xmltree.MustParseXML(bytes.NewBufferString(cdrXmlBroadsoft), optsNotStrict)
	cdrs := goxpath.MustExec(xp, xmlTree, nil)
	cdrWithoutUserNr := cdrs[0]
	if _, err := elementText(cdrWithoutUserNr, "cdrData/basicModule/userNumber"); err != utils.ErrNotFound {
		t.Error(err)
	}
	cdrWithUser := cdrs[1]
	if val, err := elementText(cdrWithUser, "cdrData/basicModule/userNumber"); err != nil {
		t.Error(err)
	} else if val != "1001" {
		t.Errorf("Expecting: 1001, received: %s", val)
	}
	if val, err := elementText(cdrWithUser, "/cdrData/centrexModule/locationList/locationInformation/locationType"); err != nil {
		t.Error(err)
	} else if val != "Primary Device" {
		t.Errorf("Expecting: <Primary Device>, received: <%s>", val)
	}
}