// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXMLWithFiles
977749
func (c *Connect) DomainCreateXMLWithFiles(xmlConfig string, files []os.File, flags DomainCreateFlags) (*Domain, error) {
	cXml := C.CString(string(xmlConfig))
	defer C.free(unsafe.Pointer(cXml))
	cfiles := make([]C.int, len(files))
	for i := 0; i < len(files); i++ {
		cfiles[i] = C.int(files[i].Fd())
	}
	var err C.virError
	ptr := C.virDomainCreateXMLWithFilesWrapper(c.ptr, cXml, C.uint(len(files)), (&cfiles[0]), C.uint(flags), &err)
	if ptr == nil {
		return nil, makeError(&err)
	}
	return &Domain{ptr: ptr}, nil
}
400052
func (service *BaseHTTPService) SetCrossDomainXMLContent(content []byte) {
	service.crossDomainXMLFile = ""
	service.crossDomainXMLContent = content
}
44746
func CreateXMLDecoder(input io.Reader, strict bool) *xml.Decoder {
	// drop any chars that will blow up the xml decoder and replace with a space
	input = filter.NewReader(input, filter.XML10Filter(filter.SpaceChar))
	decoder := xml.NewDecoder(input)
	decoder.Strict = strict
	// this only gets used when a proper xml header is used
	decoder.CharsetReader = charset.NewReaderLabel
	return decoder
}
307169
func (c *Context) BindXML(obj interface{}) error {
	return c.MustBindWith(obj, binding.XML)
}
134475
func (logs *Logs) InitFromXMLFile(path string) error {
	cfg, err := config.ParseXMLFile(path)
	if err != nil {
		return err
	}
	return logs.Init(cfg)
}
152166
func (c *Context) ShouldBindXML(obj interface{}) error {
	return c.ShouldBindWith(obj, binding.XML)
}
220504
func (c *Connect) InterfaceDefineXML(xmlConfig string, flags uint32) (*Interface, error) {
	cXml := C.CString(string(xmlConfig))
	defer C.free(unsafe.Pointer(cXml))
	var err C.virError
	ptr := C.virInterfaceDefineXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
	if ptr == nil {
		return nil, makeError(&err)
	}
	return &Interface{ptr: ptr}, nil
}
1053772
func (ctx *Context) ServeXML(obj interface{}) error {
	encoder := xml.NewEncoder(ctx)
	ctx.Header().Set("Content-Type", "application/xml; charset=UTF-8")
	err := encoder.Encode(obj)
	if err != nil {
		ctx.Header().Del("Content-Type")
	}
	return err
}
1295825
func (o *OOList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	ooListElement := xml.StartElement{Name: xml.Name{Local: "INVOOLIST"}}
	if err := e.EncodeToken(ooListElement); err != nil {
		return err
	}
	for _, openorder := range *o {
		start := xml.StartElement{Name: xml.Name{Local: openorder.OrderType()}}
		switch oo := openorder.(type) {
		case OOBuyDebt:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOBuyMF:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOBuyOpt:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOBuyOther:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOBuyStock:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOSellDebt:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOSellMF:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOSellOpt:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOSellOther:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOSellStock:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		case OOSwitchMF:
			if err := e.EncodeElement(&oo, start); err != nil {
				return err
			}
		default:
			return errors.New("Invalid OOLIST child type: " + oo.OrderType())
		}
	}
	if err := e.EncodeToken(ooListElement.End()); err != nil {
		return err
	}
	return nil
}
1344108
func NewFile() *File {
	file := make(map[string][]byte)
	file["_rels/.rels"] = []byte(XMLHeader + templateRels)
	file["docProps/app.xml"] = []byte(XMLHeader + templateDocpropsApp)
	file["docProps/core.xml"] = []byte(XMLHeader + templateDocpropsCore)
	file["xl/_rels/workbook.xml.rels"] = []byte(XMLHeader + templateWorkbookRels)
	file["xl/theme/theme1.xml"] = []byte(XMLHeader + templateTheme)
	file["xl/worksheets/sheet1.xml"] = []byte(XMLHeader + templateSheet)
	file["xl/styles.xml"] = []byte(XMLHeader + templateStyles)
	file["xl/workbook.xml"] = []byte(XMLHeader + templateWorkbook)
	file["[Content_Types].xml"] = []byte(XMLHeader + templateContentTypes)
	f := &File{
		sheetMap:   make(map[string]string),
		Sheet:      make(map[string]*xlsxWorksheet),
		SheetCount: 1,
		XLSX:       file,
	}
	f.CalcChain = f.calcChainReader()
	f.Comments = make(map[string]*xlsxComments)
	f.ContentTypes = f.contentTypesReader()
	f.DrawingRels = make(map[string]*xlsxWorkbookRels)
	f.Drawings = make(map[string]*xlsxWsDr)
	f.Styles = f.stylesReader()
	f.DecodeVMLDrawing = make(map[string]*decodeVmlDrawing)
	f.VMLDrawing = make(map[string]*vmlDrawing)
	f.WorkBook = f.workbookReader()
	f.WorkBookRels = f.workbookRelsReader()
	f.WorkSheetRels = make(map[string]*xlsxWorkbookRels)
	f.Sheet["xl/worksheets/sheet1.xml"], _ = f.workSheetReader("Sheet1")
	f.sheetMap["Sheet1"] = "xl/worksheets/sheet1.xml"
	f.Theme = f.themeReader()
	return f
}
24490
func (p *StoragePool) GetXMLDesc(flags StorageXMLFlags) (string, error) {
	var err C.virError
	result := C.virStoragePoolGetXMLDescWrapper(p.ptr, C.uint(flags), &err)
	if result == nil {
		return "", makeError(&err)
	}
	xml := C.GoString(result)
	C.free(unsafe.Pointer(result))
	return xml, nil
}
1352234
func (f *File) setContentTypePartVMLExtensions() {
	vml := false
	content := f.contentTypesReader()
	for _, v := range content.Defaults {
		if v.Extension == "vml" {
			vml = true
		}
	}
	if !vml {
		content.Defaults = append(content.Defaults, xlsxDefault{
			Extension:   "vml",
			ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing",
		})
	}
}
989525
func (c *Connect) StoragePoolCreateXML(xmlConfig string, flags StoragePoolCreateFlags) (*StoragePool, error) {
	cXml := C.CString(string(xmlConfig))
	defer C.free(unsafe.Pointer(cXml))
	var err C.virError
	ptr := C.virStoragePoolCreateXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
	if ptr == nil {
		return nil, makeError(&err)
	}
	return &StoragePool{ptr: ptr}, nil
}
1054082
func (s *DomainSnapshot) GetXMLDesc(flags DomainSnapshotXMLFlags) (string, error) {
	var err C.virError
	result := C.virDomainSnapshotGetXMLDescWrapper(s.ptr, C.uint(flags), &err)
	if result == nil {
		return "", makeError(&err)
	}
	xml := C.GoString(result)
	C.free(unsafe.Pointer(result))
	return xml, nil
}
1152674
func CreateUVMScratch(imagePath, destDirectory, vmID string) error {
	sourceScratch := filepath.Join(imagePath, `UtilityVM\SystemTemplate.vhdx`)
	targetScratch := filepath.Join(destDirectory, "sandbox.vhdx")
	logrus.Debugf("uvm::CreateUVMScratch %s from %s", targetScratch, sourceScratch)
	if err := copyfile.CopyFile(sourceScratch, targetScratch, true); err != nil {
		return err
	}
	if err := wclayer.GrantVmAccess(vmID, targetScratch); err != nil {
		os.Remove(targetScratch)
		return err
	}
	return nil
}
727899
func RunEditOnCreate(f cmdutil.Factory, printFlags *genericclioptions.PrintFlags, recordFlags *genericclioptions.RecordFlags, ioStreams genericclioptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions) error {
	editOptions := editor.NewEditOptions(editor.EditBeforeCreateMode, ioStreams)
	editOptions.FilenameOptions = *options
	editOptions.ValidateOptions = cmdutil.ValidateOptions{
		EnableValidation: cmdutil.GetFlagBool(cmd, "validate"),
	}
	editOptions.PrintFlags = printFlags
	editOptions.ApplyAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag)
	editOptions.RecordFlags = recordFlags

	err := editOptions.Complete(f, []string{}, cmd)
	if err != nil {
		return err
	}
	return editOptions.Run()
}
1074363
func (p *printer) createAttrPrefix(url string) string {
	if prefix := p.attrPrefix[url]; prefix != "" {
		return prefix
	}

	// The "http://www.w3.org/XML/1998/namespace" name space is predefined as "xml"
	// and must be referred to that way.
	// (The "http://www.w3.org/2000/xmlns/" name space is also predefined as "xmlns",
	// but users should not be trying to use that one directly - that's our job.)
	if url == xmlURL {
		return xmlPrefix
	}

	// Need to define a new name space.
	if p.attrPrefix == nil {
		p.attrPrefix = make(map[string]string)
		p.attrNS = make(map[string]string)
	}

	// Pick a name. We try to use the final element of the path
	// but fall back to _.
	prefix := strings.TrimRight(url, "/")
	if i := strings.LastIndex(prefix, "/"); i >= 0 {
		prefix = prefix[i+1:]
	}
	if prefix == "" || !isName([]byte(prefix)) || strings.Contains(prefix, ":") {
		prefix = "_"
	}
	if strings.HasPrefix(prefix, "xml") {
		// xmlanything is reserved.
		prefix = "_" + prefix
	}
	if p.attrNS[prefix] != "" {
		// Name is taken. Find a better one.
		for p.seq++; ; p.seq++ {
			if id := prefix + "_" + strconv.Itoa(p.seq); p.attrNS[id] == "" {
				prefix = id
				break
			}
		}
	}

	p.attrPrefix[url] = prefix
	p.attrNS[prefix] = url

	p.WriteString(`xmlns:`)
	p.WriteString(prefix)
	p.WriteString(`="`)
	EscapeText(p, []byte(url))
	p.WriteString(`" `)

	p.prefixes = append(p.prefixes, prefix)

	return prefix
}