-
Add xmlns to node
hi
im using the following
Dim _xdoc As New Xml.XmlDocument
Dim _xmlString As New System.Text.StringBuilder
_xmlString.Append("<configuracao'")
_xmlString.Append("<oracle>")
_xmlString.Append("<utilizador>tony</utilizador>")
_xmlString.Append("<palavrapasse>tony</palavrapasse>")
_xmlString.Append("<instancia>MYINSTANCE</instancia>")
_xmlString.Append("<enderecoservidor>10.1.1.1</enderecoservidor>")
_xmlString.Append("</oracle>")
_xmlString.Append("</configuracao>")
_xdoc.LoadXml(_xmlString.ToString())
Dim xmldecl As Xml.XmlDeclaration
xmldecl = _xdoc.CreateXmlDeclaration("1.0", "Windows-1252", "yes")
Dim root As Xml.XmlElement = _xdoc.DocumentElement
_xdoc.InsertBefore(xmldecl, root)
_xdoc.Save("CONFIGURACAO.xml")
this is working fine for me and it produces this document :
<?xml version="1.0" encoding="Windows-1252" standalone="yes" ?>
<configuracao>
<oracle>
<utilizador>tony</utilizador>
<palavrapasse>tony</palavrapasse>
<instancia>MYINSTANCE</instancia>
<enderecoservidor>10.1.1.1</enderecoservidor>
</oracle>
</configuracao>
i would like to have the xmlns add to the first node
<?xml version="1.0" encoding="Windows-1252" standalone="yes" ?>
<configuracao xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.01_01">
<oracle>
<utilizador>tony</utilizador>
<palavrapasse>tony</palavrapasse>
<instancia>MYINSTANCE</instancia>
<enderecoservidor>10.1.1.1</enderecoservidor>
</oracle>
</configuracao>
any ideas ? thks in advanced
rgds
rui
-
Re: Add xmlns to node
never mind
i found the solution on the C# forum.
just added
_xdoc.DocumentElement.SetAttribute("xmlns", "urn:OECD:StandardAuditFile-Tax:PT_1.01_01")
:)
rgds
rui
-
Re: Add xmlns to node
Write out an XmlNode object with your Xml, then use the InsertBefore/After methods on the XmlDocument object.