patricktoulon
XLDnaute Barbatruc
bonjour  à tous
j'ai un petit soucis que je n'arrive pas a résoudre
a la création du xml (encodé en utf-8/utf-16) le caractère "&" se transforme en "&"
donc la chaine 
 se transforme en 
quelqu'un aurait une idée ?(pour garder "
")
	
	
	
	
	
		
je me casse la tête depuis hier avec ça 🤣🤣
	
		
			
		
		
	
				
			j'ai un petit soucis que je n'arrive pas a résoudre
a la création du xml (encodé en utf-8/utf-16) le caractère "&" se transforme en "&"
donc la chaine 
 se transforme en 
quelqu'un aurait une idée ?(pour garder "
")
		VB:
	
	
	Sub test()
Dim DocXml, balise, enfant, oCreation
Set DocXml = CreateObject("Microsoft.XMLDOM")    'creation
    Set balise = DocXml.appendchild(DocXml.createelement("balise"))
     balise.setAttribute "groupage", "do not"
    balise.setAttribute ("id"), "provix1"
    Set oCreation = DocXml.createProcessingInstruction("xml", "version=""1.0"" encoding=""UTF-8"" standalone=""yes""")    'creation de l'entete du process
    DocXml.InsertBefore oCreation, DocXml.ChildNodes.Item(0)    'insertion parametre process
    Set enfant = DocXml.createelement("enfant"): enfant.setAttribute "commentaire", "juste un test 
 de commentaire": enfant.setAttribute ("id"), "provix2"
    balise.appendchild (enfant)
SaveFormatDocToFileXL DocXml, ThisWorkbook.Path & "\exoamp.xml"
End Sub
'enregistrer le xml  au format utf-8 et indenté
Public Sub SaveFormatDocToFileXL(ByVal doc, ByVal FileName As String)
    Dim rdrdom As Object, StreamFormaté As Object, wtrFormatted As Object
    Set rdrdom = CreateObject("MSXML2.SAXXMLReader.6.0")
    Set StreamFormaté = CreateObject("ADODB.Stream")
    Set wtrFormatted = CreateObject("MSXML2.MXXMLWriter")
    With StreamFormaté
        .Open
        .Type = 1    'adTypeBinary
        With wtrFormatted
            .omitXMLDeclaration = False
            .standalone = True
            .byteOrderMark = True    'If not set (even to False) then
            '.encoding is ignored.
            .Encoding = "UTF-8"    'Even if .byteOrderMark = True
            'UTF-8 never gets a BOM.
            .indent = True
            .output = StreamFormaté
            With rdrdom
                Set .contentHandler = wtrFormatted
                Set .dtdHandler = wtrFormatted
                Set .errorHandler = wtrFormatted
                .putProperty "http://xml.org/sax/properties/lexical-handler", wtrFormatted
                .putProperty "http://xml.org/sax/properties/declaration-handler", wtrFormatted
                .Parse doc
            End With
        End With
        If Dir(FileName) <> "" Then Kill FileName
    
        .SaveToFile FileName
        .Close
    End With
    Set rdrdom = Nothing
    Set StreamFormaté = Nothing
    Set wtrFormatted = Nothing
End Sub
	je me casse la tête depuis hier avec ça 🤣🤣