je ce code pour les paramètres:Comment faire XmlTextWriter et XmlWriterSettings travailler ensemble
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.OmitXmlDeclaration = True
settings.NewLineOnAttributes = True
Ensuite, je le code pour l'écrivain:
Dim xml As New XmlTextWriter(Server.MapPath("output.xml"), enc)
S'il vous plaît pouvez-vous me dire comment je fais les paramètres s'appliquent à l'écrivain? Merci beaucoup, Phil.
EDIT: Code échantillon
Sub writexml_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Try
'Vars
Dim securityid As String = Input_securityid.Text
Dim enc As Encoding
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.OmitXmlDeclaration = True
settings.NewLineOnAttributes = True
settings.Encoding = enc
'Declare the writer and set file name/settings
Dim xml As XmlWriter = XmlWriter.Create(Server.MapPath("output.xml"), settings)
'start document
xml.WriteStartDocument()
xml.WriteComment("")
'start envelope
xml.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/")
'start body
xml.WriteStartElement("soap", "Body", Nothing)
xml.WriteAttributeString("xmlns", "ns1", Nothing, "http://its/foo.wsdl")
'start biographical capture
xml.WriteStartElement("ns1:biographicalcaptureElement")
'start securityid
xml.WriteStartElement("ns1:securityid")
xml.WriteValue(securityid)
'end securityid
xml.WriteEndElement()
'start requestdata
xml.WriteStartElement("ns1:requestdata")
'end requestdata
xml.WriteEndElement()
'end biographical capture
xml.WriteEndElement()
'end body
xml.WriteEndElement()
'end envelope
xml.WriteEndElement()
'end document
xml.WriteEndDocument()
'clean up
xml.Flush()
xml.Close()
Catch ex As Exception
errorlbl.Text = ex.ToString
Finally
errorlbl.Text = ("Created file ok")
End Try
End Sub
Il fonctionne très bien si je l'utilise;
Dim xml As New XmlTextWriter(Server.MapPath("output.xml"), enc)
le xml est produit, mais les paramètres ne sont pas appliqués.
Merci pour l'aide Andy, très apprécié. J'ai maintenant la configuration de code comme vous le suggérez, mais quand j'essaye de générer le xml il revient vide. Dim xml As XmlWriter = XmlWriter.Create (Server.MapPath ("output.xml"), paramètres) Est-ce correct? Merci – Phil
Ouais cela semble bien - pouvez-vous éditer votre question et fournir l'exemple de code pertinent? –
Merci, ont ajouté l'exemple de code. – Phil