XMLWriter and XMLDocument

Okay

I am using an XMLDocument object to process several thousands of lodgements (from a database)

I am trying to output it from an XML Document to a file using the XmlDocument.WriteTo() method with an XmlWriter. It writes 131kB and then cuts out halfway through an element

Is this a limitation of XmlDocument.WriteTo() ? What would be a better way to output it

Thanks
0
anonymous (74722)
5/12/2004 8:56:08 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
761 Views

Similar Articles

[PageSpeed] 11

Ensure you're calling XmlWriter.Close() to cause the buffered writes to be
flushed to the underlying stream/textwriter.

-- 
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com

"David Withnall" <anonymous@discussions.microsoft.com> wrote in message
news:041B3C13-C1AD-4599-BD11-EE1A19895821@microsoft.com...
> Okay,
>
> I am using an XMLDocument object to process several thousands of
lodgements (from a database).
>
> I am trying to output it from an XML Document to a file using the
XmlDocument.WriteTo() method with an XmlWriter. It writes 131kB and then
cuts out halfway through an element.
>
> Is this a limitation of XmlDocument.WriteTo() ? What would be a better way
to output it?
>
> Thanks


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.679 / Virus Database: 441 - Release Date: 09/05/2004


0
kzuAT4605 (35)
5/12/2004 11:17:04 AM
From msdn:

XmlWriter.Flush Method:
This is called instead of Close when you want to write 
more to the underlying stream without losing what is still 
in the buffer.

Sonu
My Blog: http://weblogs.asp.net/sonukapoor/


>-----Original Message-----
>Okay,
>
>I am using an XMLDocument object to process several 
thousands of lodgements (from a database).
>
>I am trying to output it from an XML Document to a file 
using the XmlDocument.WriteTo() method with an XmlWriter. 
It writes 131kB and then cuts out halfway through an 
element.
>
>Is this a limitation of XmlDocument.WriteTo() ? What 
would be a better way to output it?
>
>Thanks
>.
>
0
vikasde (26)
5/12/2004 9:39:44 PM
Reply:

Similar Artilces:

From TreeView To XMLDocument
How do I save the contents of a TreeView to a XML Document? "Casper JH Erasmus" <ceit@mweb.co.za> wrote in message news:KPmdnZ_XbbRYwqnfRVn-jg@is.co.za... > How do I save the contents of a TreeView to a XML Document? Like any WinForms control, you've probably found XmlSerialization won't cut it because of references to IntPtrs (in this case). When you're only interested in preserving the node hierarchy of the TreeView, then the most direct means is by traversing the nodes in the TreeNodeCollections and adding XmlElements to an XmlDocument as you go (they al...

XmlDocument.LoadXml Errors with &amp in string
I have a project in which I get xml posted via a hidden form field (data=<xml></xml>). People are entering names like Bill & Sandy Smith. this is coming over as: <NameInfo><FamilyName><FamilyNames>David &amp; Karen</FamilyNames><Surname>Adams</Surname></FamilyName></NameInfo> When I try to load this up in a XmlDocument it blows up. string xmlData = Request.Form["RequestData"]; dom.LoadXml(xmlData); results with this: "This is an unexpected token. The expected token is 'EndElement'. Line 1, position...

generating an XmlDocument from an XmlWriter
hi, I would like to make an XmlWriter write directly into an XmlDocument rather than writing it to a stream and then having to load it into a document. in the documentation for XmlWriter it rather tantalizingly says: "... For example, if you are using the XmlWriter to populate an XmlDocument ...." (just google for that phrase to see it in context) which implies that it it possible to do what I want, but I can't see any way of doing that. Andy Andy Fish wrote: > hi, > > I would like to make an XmlWriter write directly into an XmlDocument rather > than writ...

XMLWriter and NumberDecimalSeparator
Hello, All! Is it possible to change parameters of locale for writing XML file (with XMLTextWriter)? I want to change NumberDecimalSeparator from "," to "." Regards, Vyacheslav ...

XmlDocument.SelectSingleNode XPathException
Hi; I am calling SelectSingleNode("/xml/s:Schema/s:ElementType/@name") where "/xml/s:Schema/s:ElementType/@name is a legit xpath statement (xml is the name of the rootnode) and that xpath statement works fine on the document in XmlSpy. However, when I call this is .NET 1.1, I get the following exception: XPathException {"Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function."} Any ideas? -- thanks - dave Hi Dave, Welcome to MSDN newsgroup. As for the XPathException you encountered, it is caused by the namespa...

Help with XMLDocument
Hi. I've got an XML file similar in construct to: <Stuff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="Stuff" xsi:schemaLocation="Stuff all-stuff.xsd"> <Foo ...> Foo Elements </Foo> <Bar ...> Bar Elements </Bar> <FooBar ...> FooBar Elements </FooBar> </Stuff> So using XMLDocument's SelectSingleNode or SelectNodes I can't for the life of me get a Node or Node collection of <Foo>,<Bar> or any for that matter. I've tr...

Bulk add prefix to XmlDocument
Hi All, I have an XML document that looks like this: <book> <title>Foo</title> <description> <div xmlns="http://www.w3.org/1999/xhtml"> <p>Body this is the body</p> </div> </description> </book> Now I need to append this document into another XmlDocument object. To correctly do this I want to add a namespace on the original XmlDocument with "book" as it prefix. But I don't want change the namespace of the <div> since it has a namespace defined on it. So for example the result sh...

XslTransform from one XmlDocument to another...
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public XmlDocument TransformXmlDoc(XmlDocument docToTransform, string xsltFilePath) { //load the xslt XslTransform trans = new XslTransform(); trans.Load(xsltFilePath); //create a new xmlDoc XmlDocument docToReturn = new XmlDocument(); //transform the original doc into a memorystream Stream str = new MemoryStream(); XmlWriter xWriter = new XmlTextWriter(str,Encoding.UTF8); trans.Transform(docToTransfo...

XmlWriter.WriteAttributeString()
The WriteAttributeString() method(s) of System.Xml.XmlWriter Class is embedding the Value parameter within double quotes. Is it possible to change this behaviour such that the Value is instead put within Single Quotes (Apostrophes)? -- Regards Senthil SS. SenthilSS wrote: > The WriteAttributeString() method(s) of System.Xml.XmlWriter Class is > embedding the Value parameter within double quotes. Is it possible to change > this behaviour such that the Value is instead put within Single Quotes > (Apostrophes)? Take a look at the QuoteChar property. -- Oleg Tkachenko [XML ...

XmlDocument.ReadNode() breaking
Hi... A colleague just referred this question to me. He's getting an xml file from another party, which he's trying to process into another dom using an XmlTextReader and XmlDocument.ReadNode(). The problem is that it's breaking and he doesn't understand why. I didn't exactly either, which is why I'm posting a question here. First, his program just creates a new dom using new document like this: XmlDocument xml = new XmlDocument(); XmlElement root = xml.CreateElement("root"); xml.AppendChild(root); Then it starts sucking in various xml files on disk ...

XmlWriter localization
Hi all, i have to generate a xml file from a product table using the XmlWriter Class. I want to put out de product name for different languages, countries. The recipient of the generatet xml file espects something like that: <name xml:lang="en-US">product name</name> <name xml:lang="de-DE">Produktname</name> I have no idea how to realize this:( I hope someone can help me with this issue. Thanks Hi Peter, Hmm... did you mean this: Writer.WriteStartElement("name"); Writer.WriteAttributeString("xml", "lang", st...

Deserialization Problems Using XmlWriter vs. StringReader
I'm experiencing issues where XmlSerialier.Deserialize throws an exception when attempting to use a MemoryStream built with an XmlWriter vs. a standalone StringReader. It is attempting to deserialize a complex object. Here is what I have: 0. Environment: Visual Studio 2005, VB.Net. I won't go into the gory details of my complex object, just suffice to say that I need to return XML instead of the object directly from the web service. I'm also not including all of the code around things (try..catches, etc.) 1. I've defined a object built by using the Xsd.exe tool against a ...

XmlDocument.WriteTo thread safety
I'm reading a xmldocument in from the file system and using xmldocument.writeto(xmltextwriter) to stream the xml data to the response.outputstream. From what i've read, reading an xmldocument is thread safe but does the writeto() method require a lock? Thanks in advance! Charles.Deisler@gmail.com wrote: > I'm reading a xmldocument in from the file system and using > xmldocument.writeto(xmltextwriter) to stream the xml data to the > response.outputstream. From what i've read, reading an xmldocument is > thread safe but does the writeto() method require a lock? ...

Transforming to an XmlWriter
The following blog gives a neat example of how to transform directly into a node: http://blogs.msdn.com/xmlteam/ However, the code doesn't seem to work as it is presented in the blog. I have put together the following three test cases to show this. The first two work correctly, the last one doesn't. BTW...the last one is codes according to the blog entry. ------------------------------ System.Xml.Xsl.XslCompiledTransform xslt = new System.Xml.Xsl.XslCompiledTransform(); System.Xml.XmlDocument OutputDoc = null; System.Xml.XmlWriter w = null; ...

XmlWriter.WriteString() problem.
According to the Microsoft documentation, the .NET class System.Xml.XmlWriter.WriteString() does the following: "Character values in the range 0x-0x1F (excluding white space characters 0x9, 0xA, and 0xD) are replaced with numeric character entities (&#0; through &#0x1F)." However, when we call WriteString() in an application we have written, we are seeing the following exception being thrown: System.ArgumentException: '', hexadecimal value 0x12, is an invalid character. at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int32 ch, Byte* pDst, Boolean entiti...

XMLWriter and XMLDocument
Okay I am using an XMLDocument object to process several thousands of lodgements (from a database) I am trying to output it from an XML Document to a file using the XmlDocument.WriteTo() method with an XmlWriter. It writes 131kB and then cuts out halfway through an element Is this a limitation of XmlDocument.WriteTo() ? What would be a better way to output it Thanks Ensure you're calling XmlWriter.Close() to cause the buffered writes to be flushed to the underlying stream/textwriter. -- Daniel Cazzulino [MVP XML] Clarius Consulting SA http://weblogs.asp.net/cazzu http://aspnet2.com ...

System.Xml.XmlDocument with (x)html entities
Hello all, I'm having a bit of a problem with System.Xml.XmlDocument. The scenario is as follows: I receive a dataset containing some data fetched from database. I can retrieve a string containing the data with Dataset.GetXml method. Inside the xml document, in a datatable field, I have an xhtml document that may contain xhtml entities (for example &nbsp; or &apos;). When I do a XmlDocument.LoadXml, these xhtml entities crash the LoadXml method. I've tried looking into the XmlResolver class, but haven't found a way to get it to work with XmlDocument. Anyone? TIA, S...

XmlWriter with ConformanceLevel.Fragment
Hi I keep getting error : WriteStartDocument cannot be called on writers created with ConformanceLevel.Fragment. The code that I have is very simple. SimpleClass c = new SimpleClass(); c.Name = "TestName"; XmlSerializer serializer = new XmlSerializer(typeof(SimpleClass)); MemoryStream stream =new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.ConformanceLevel = ConformanceLevel.Fragment; settings.Encoding = Encoding.ASCII; XmlWriter writer = XmlWriter.Create(stream,settings); serializer.Serialize(write...

"In Use" exception on XMLDocument.Save
When using XMLDocument.Save(strFileName) in .NET 2005, is there a way to check (or trap) and see if the file is in use by another. I am using VB.NET. Currently it just bombs and says the filename is in use by another. I want to check or trap for this rather than blow-up. I tried using a Try...Catch, but it bombs deep in the DOM, where I don't have control of it. Here is the Code Me.XMLDocument.Save(strFileName) Terry wrote: > I tried using a Try...Catch, > but it bombs deep in the DOM, where I don't have control of it. > > Here is the Code > > Me.XM...

XmlWriter newbie question
I'm trying, for the first time, to write XML to a string that will be sent out to a web service. According to the docs I have found... An XmlWriter needs a XmlTextWriter that needs a StreamWriter that needs a stream. (is it really this hard?) So I'm defining... System.IO.Stream astream; TextWriter myw = new StreamWriter(astream); <--this says astream is an unassigned variable XmlTextWriter mytw = new XmlTextWriter(myw); so it won't compile because it says astream is not defined. Are there any examples anywhere on how to write xml to a string, or a stream? -- Regards,...

How to use XmlDocument?
Hello - I have been searching the Internet for some help with the XmlDocument but have not found an example that really helps me. What I essentially want to do is parse the following XML to extract the offset and type fields of a parameter by specifying "ABC", "Data A", "Field A" ... <Configuration file="xyz.ini"> <Source name="ABC"> <Subset name="Data A"> <Parameter name="FieldA" offset="0" type="double"> <Parameter name="FieldB" offs...

XmlDocument.LoadXml and namespaces
Hi; Once I have loaded an xml file into a DOM, is there any way to then get any namespace declarations that were in the xml file? Or are those just discarded as the DOM is populated? And if you can't get it from the DOM, any other way to get the namespace(s)? I'm assuming doing a SAX read which returns each element including NameSpaces and pull it form that (and build up the DOM at the same time)? In my case I get a Stream so I can't read it twice as the Stream may not support reset. And it may have NS elements - but I don't know if there are any or what they are excep...

How to use xmlwriter to add an attribute to any element?
I want to make my XML as such: <parentItem> <childItem attribute="myAttribute">myContent</childItem> </parentItem> I thought I could just do this: objXMLWriter.WriteElementString("childItem", "myContent") objXMLWriter.WriteAttributeString("attribute", "myAttribute") But...I get an error. And I found this that explains why: http://weblogs.asp.net/sonukapoor/pages/204572.aspx However, it only explains why it happens, not how to actually do what I want. From what I can tell, WriteAttributeString can ONLY be applie...

XMLWriter and NumberDecimalSeparator #2
Hello, All! Is it possible to change parameters of locale for writing XML file (with XMLTextWriter)? I want DataSet.WriteXML() to use NumberDecimalSeparator "." instead of "," Regards, Vyacheslav Vyacheslav Lanovets wrote: > I want DataSet.WriteXML() to use NumberDecimalSeparator "." instead of "," I don't think the result of WriteXml depends on the locale (or culture as .NET calls it), for instance the output in the following example is always the same, even if the culture is changed: DataSet dataSet = new DataSet("DoubleT...

Avoiding the use of XmlDocument
I have an application which sends messages to an external application. All data is submitted as a string in an Xml format specified by the other application, along with some custom elements we have added to assist in trouble shooting. The format is below <AppName><Data><![CDATA[our data goes here]]></Data><CustomField1>field 1 data here</CustomField1><CustomField2>field 2 data here</CustomField2></AppName Currently this Xml is being created dynamically each time a message is being sent, using an XmlTextWriter. What I would like to do is defi...