Пример #1
0
//	Attempts to xml.Unmarshal() all files in the "infiles" sub-directory of the specified directory path into the interface{} structure returned by the specified constructor.
//	For each such input file, then attempts to xml.MarshalIndent() said structure back into a new output XML file with the same name, in the "outfiles" sub-directory of the specified directory path.
func TestViaRemarshal(dirPath string, makeEmptyDoc func() interface{}) {
	var dirPathInFiles = filepath.Join(dirPath, "infiles")
	var dirPathOutFiles = filepath.Join(dirPath, "outfiles")
	var loadXmlDocFile = func(filename string, keepRecursing bool) bool {
		log.Printf("Loading %s", filename)
		doc, dataOrig := makeEmptyDoc(), uio.ReadBinaryFile(filename, true)
		err := xml.Unmarshal(dataOrig, doc)
		if err != nil {
			panic(err)
		}
		if OnDocLoaded != nil {
			OnDocLoaded(doc)
		}
		outFileName := filepath.Join(dirPathOutFiles, filepath.Base(filename))
		log.Printf("Writing %s", outFileName)
		dataFaks, err := xml.MarshalIndent(doc, "", "\t")
		if err != nil {
			panic(err)
		}
		uio.WriteTextFile(outFileName, strings.Trim(string(dataFaks), " \r\n\t"))
		log.Printf("Verifying...")
		if errs := verifyDocs(dataOrig, dataFaks); len(errs) > 0 {
			for _, err = range errs {
				log.Printf("%v", err)
			}
		}
		return keepRecursing
	}
	uio.WalkDirectory(dirPathInFiles, "", loadXmlDocFile, true)
}
Пример #2
0
func convert(srcFilePath, dstFilePath string) {
	var (
		err     error
		data    []byte
		outFile *os.File
	)
	log.Printf("SRC: %s\n", srcFilePath)
	data = uio.ReadBinaryFile(srcFilePath, true)
	if outFile, err = os.Create(dstFilePath); err != nil {
		panic(err)
	}
	defer outFile.Close()
	if data, err = conv.ConvertBytes(data); err != nil {
		panic(err)
	}
	log.Printf("\tOUT: %s\n", dstFilePath)
	outFile.Write(data)
}
Пример #3
0
func loadSpecXml() {
	specDoc = xmlx.New()
	if err := specDoc.LoadBytes(uio.ReadBinaryFile(util.GopathSrcGithub("go3d", "go-ngine", "_tools", "buildtools", "ng-gogl-imp-version-checker", "opengl.xml"), true), nil); err != nil {
		panic(err)
	}
}