Buongiorno a tutti io ho il seguente codice io utilizzo VB6
codice:Option Explicit Dim oDoc As DOMDocument Dim DOCINPATH As String Dim XMLOUTPATH As String Dim DOCOUTPATH As String Private Sub cmdCreateXML_Click() Dim xmlProcessingInstruction As MSXML2.IXMLDOMProcessingInstruction Dim oEle As IXMLDOMElement Dim oRoot As IXMLDOMElement Dim objXSelemento As IXMLDOMElement Dim oNode As IXMLDOMNode Dim objXSelementoA As IXMLDOMAttribute Dim xscomplexType As IXMLDOMElement Dim xssequence As IXMLDOMElement Dim xselement As IXMLDOMElement Dim xselementA As IXMLDOMAttribute Dim commento As IXMLDOMComment Dim xselementname As IXMLDOMElement Dim objRootElem As IXMLDOMElement Dim objMemberElem As IXMLDOMElement Dim objMemberRel As IXMLDOMAttribute Dim objMemberName As IXMLDOMElement DOCINPATH = App.Path & "\DocInput.doc" XMLOUTPATH = App.Path & "\AlexProvaCooperante.xml" Call ReleaseObjects Set oDoc = New DOMDocument oDoc.resolveExternals = True 'prova nuovo processing encoding Set xmlProcessingInstruction = oDoc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'") oDoc.appendChild xmlProcessingInstruction Set xmlProcessingInstruction = Nothing ' Create processing instruction and document root Set objMemberElem = oDoc.createElement("Pratica") oDoc.appendChild objMemberElem ' Creates Attribute to the Member Element Set objMemberRel = oDoc.createAttribute("xmlns") objMemberRel.nodeValue = "Automobile Club d'Italia: Home page" objMemberElem.setAttributeNode objMemberRel Set objMemberRel = oDoc.createAttribute("xmlns:xsi") objMemberRel.nodeValue = "XML Schema" objMemberElem.setAttributeNode objMemberRel Set objMemberRel = oDoc.createAttribute("xsi:schemaLocation") objMemberRel.nodeValue = "Automobile Club d'Italia: Home page" objMemberElem.setAttributeNode objMemberRel Set xscomplexType = oDoc.createElement("IdentificativoPratica") objMemberElem.appendChild xscomplexType Set xssequence = oDoc.createElement("IdPratica") xssequence.Text = "ALEX" xscomplexType.appendChild xssequence ' Save xml file oDoc.save XMLOUTPATH MsgBox XMLOUTPATH & " is created for you." End Sub Function ReadBinData(ByVal strFileName As String) As Variant Dim lLen As Long Dim iFile As Integer Dim arrBytes() As Byte Dim lCount As Long Dim strOut As String 'Read from disk iFile = FreeFile() Open strFileName For Binary Access Read As iFile lLen = FileLen(strFileName) ReDim arrBytes(lLen) 'ReDim arrBytes(lLen - 1) Get iFile, , arrBytes Close iFile ReadBinData = arrBytes End Function Private Sub WriteBinData(ByVal strFileName As String) Dim iFile As Integer Dim arrBuffer() As Byte Dim oNode As IXMLDOMNode If Not (oDoc Is Nothing) Then ' Get the data Set oNode = oDoc.documentElement.selectSingleNode("/Root/Data") ' Make sure you use a byte array instead of variant arrBuffer = oNode.nodeTypedValue ' Write to disk iFile = FreeFile() Open strFileName For Binary Access Write As iFile Put iFile, , arrBuffer Close iFile End If End Sub Private Sub cmdGetBinary_Click() DOCOUTPATH = App.Path & "\DocOutput.doc" Set oDoc = New DOMDocument If oDoc.Load(XMLOUTPATH) = True Then ' Save the Doc as another file WriteBinData DOCOUTPATH MsgBox DOCOUTPATH & " is created for you." Else MsgBox oDoc.parseError.reason End If End Sub Private Sub Form_Unload(Cancel As Integer) ReleaseObjects End Sub Private Sub ReleaseObjects() Set oDoc = Nothing End Sub
il file xml che viene creato(il seguente):
il problema è il seguente io non vorrei che al nodo <IdentificativoPratica> venisse aggiunto l'attributo xmlns="" come capita nel file generato ma che risultasse solo il nome del nodo potete aiutarmi per favore Grazie<?xml version="1.0" encoding="UTF-8"?>
-<Pratica xmlns="http://www.aci.it/STA/Pratica"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.aci.it/STA/Pratica">
-<IdentificativoPratica xmlns="">
<IdPratica>ALEX</IdPratica>
</IdentificativoPratica>
</Pratica>

Rispondi quotando
