Net 2.0 I'm using xml to store company configuration settings in a BLOB database field. I create an xPathNavigator like this: Dim doc As XmlDocument = New XmlDocument Dim strXml As String = (-read the xml string from the db) Dim sr As New System.IO.StringReader(strXml) doc.Load(sr) xnav = doc.CreateNavigator And then use the xnav to read and set fields from the application. When I save the xml string back to the database, I loose the xml declaration "<?xml version="1.0" encoding="UTF-8" ?>" with xnav.outerxml. Is there some way to get the xml string WITH the xml declaration? Rick
Rick wrote: > Net 2.0 > > I'm using xml to store company configuration settings in a BLOB database > field. > > I create an xPathNavigator like this: > > Dim doc As XmlDocument = New XmlDocument > > Dim strXml As String = (-read the xml string from the db) > > Dim sr As New System.IO.StringReader(strXml) > > doc.Load(sr) > > xnav = doc.CreateNavigator > > And then use the xnav to read and set fields from the application. > > When I save the xml string back to the database, I loose the xml declaration > "<?xml version="1.0" encoding="UTF-8" ?>" with xnav.outerxml. > > Is there some way to get the xml string WITH the xml declaration? The XPath data model does not know about XML declarations so the XPathNavigator does not have them. With .NET the DOM model contains an XML declaration so you should use doc.OuterXml (or use the Save method of the XmlDocument doc) if you want an XML declaration. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Thanks Martin, Perhaps I will leave it as it is without the xml declaration since it is only for internal use and there seems to be no problem reading/writing to the saved document. Rick "Martin Honnen" wrote in message news:ervCjVN3HHA.5116@TK2MSFTNGP04.phx.gbl... > Rick wrote: >> Net 2.0 >> >> I'm using xml to store company configuration settings in a BLOB database >> field. >> >> I create an xPathNavigator like this: >> >> Dim doc As XmlDocument = New XmlDocument >> >> Dim strXml As String = (-read the xml string from the db) >> >> Dim sr As New System.IO.StringReader(strXml) >> >> doc.Load(sr) >> >> xnav = doc.CreateNavigator >> >> And then use the xnav to read and set fields from the application. >> >> When I save the xml string back to the database, I loose the xml >> declaration "<?xml version="1.0" encoding="UTF-8" ?>" with xnav.outerxml. >> >> Is there some way to get the xml string WITH the xml declaration? > > The XPath data model does not know about XML declarations so the > XPathNavigator does not have them. With .NET the DOM model contains an XML > declaration so you should use doc.OuterXml (or use the Save method of the > XmlDocument doc) if you want an XML declaration. > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/