xmlwriter

c# using + XmlWriter.Create = “Cannot access a closed Stream.”

断了今生、忘了曾经 提交于 2019-12-07 01:19:55
问题 Why this works: using (var ms = new MemoryStream()) { using (var dummy = new StreamWriter(ms)) { var sw = new StreamWriter(ms); sw.WriteLine("Hello World"); sw.Flush(); using (StreamReader rdr = new StreamReader(ms)) { ms.Position = 0; textBoxExc.Text = rdr.ReadToEnd(); } } } but this does not work ("Cannot access a closed Stream."): Only difference is var dummy = XmlWriter.Create(ms) instead of var dummy = new StreamWriter(ms) using (var ms = new MemoryStream()) { using (var dummy =

How to update this xml file with PHP XML reader & writer?

浪尽此生 提交于 2019-12-06 14:46:26
问题 I have the following sitemap XML which contains a list of URLs to be submitted for search engines. I took this example code from another SO answer. // Init XMLWriter $writer = new XMLWriter(); $writer->openURI(APPLICATION_PATH . '/sitemap.xml'); // document head $writer->startDocument('1.0', 'UTF-8'); $writer->setIndent(4); $writer->startElement('urlset'); $writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); // Write something // this will write: <url><loc>some url

What is the best way to create XML files in Java?

北城以北 提交于 2019-12-06 14:44:48
We are presently using dom4j to create XML files. However, I'm guessing there's something better now. If we are Java 1.6 or later, what is the best (fastest when running, simple to use) class(es) to use when writing out an XML file. I do not need to build a DOM and then write the entire DOM. I just need something that will write out the elements/attributes as I pass them to the class. thanks - dave If you just want to write an XML document having exact control over the creating of elements, attributes and other document components, you may use the XMLStreamWriter from the StAX API. Chan My 2

Write XML directly to disk and append elements

喜欢而已 提交于 2019-12-06 01:39:44
I am trying to write an XML file but it is too large to store in memory, thus I want to write to it directly to disk. I have tried using XmlWriter but there is not functionality to enable me to append to the end of the file, hence I am willing to resort to writing the XML raw using a regular file writer. Does anyone know of any file writing classes that enable me to write straight to disk and which enable me to overwrite positions inside the file? The reason is that I need to be able to write over the closing of the root element so that I may append another bit of information, but also be able

XmlWriter encoding UTF-8 using StringWriter in C#

南笙酒味 提交于 2019-12-05 11:28:42
I'm using C# to output an xml file and Im trying to set the xml encoding value to UTF-8 but its currently outputting: <?xml version="1.0"?> This is my code: public sealed class StringWriterWithEncoding: StringWriter { private readonly Encoding encoding; public StringWriterWithEncoding(Encoding encoding) { this.encoding = encoding; } public override Encoding Encoding { get { return encoding; } } } private string GetXml(JobStore jobStore) { StringWriterWithEncoding sw = new StringWriterWithEncoding(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8;

Return all attributes of an HtmlElement in Web browser

馋奶兔 提交于 2019-12-05 06:46:09
I need to get all of the attributes from my webbrowser.currently,I am using GetAttribute() but this way,I need to know the name of the attributes. Imagine I do not know what is in my webbrowser. My C# code: StringWriter strWriter = new StringWriter(); XmlWriter xWriter = XmlWriter.Create(strWriter, new XmlWriterSettings() { Indent = true }); xWriter.WriteStartElement("Items"); foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("TEXTAREA")) { xWriter.WriteStartElement("Item"); xWriter.WriteElementString("GUID", el.Id); xWriter.WriteElementString("Type", el.GetAttribute("type")

c# using + XmlWriter.Create = “Cannot access a closed Stream.”

主宰稳场 提交于 2019-12-05 05:09:28
Why this works: using (var ms = new MemoryStream()) { using (var dummy = new StreamWriter(ms)) { var sw = new StreamWriter(ms); sw.WriteLine("Hello World"); sw.Flush(); using (StreamReader rdr = new StreamReader(ms)) { ms.Position = 0; textBoxExc.Text = rdr.ReadToEnd(); } } } but this does not work ("Cannot access a closed Stream."): Only difference is var dummy = XmlWriter.Create(ms) instead of var dummy = new StreamWriter(ms) using (var ms = new MemoryStream()) { using (var dummy = XmlWriter.Create(ms)) { var sw = new StreamWriter(ms); sw.WriteLine("Hello World"); sw.Flush(); using

what's the fastest way to write XML

梦想的初衷 提交于 2019-12-05 03:59:30
I need create XML files frequently and I choose XmlWrite to do the job, I found it spent much time on things like WriteAttributeString ( I need write lots of attributes in some cases), my question is are there some better way to create xml files? Thanks in advance. Fastest way that I know is two write the document structure as a plain string and parse it into an XDocument object: string str = @"<?xml version=""1.0""?> <!-- comment at the root level --> <Root> <Child>Content</Child> </Root>"; XDocument doc = XDocument.Parse(str); Console.WriteLine(doc); Now you will have a structured and ready

How to update this xml file with PHP XML reader & writer?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 20:00:18
I have the following sitemap XML which contains a list of URLs to be submitted for search engines. I took this example code from another SO answer. // Init XMLWriter $writer = new XMLWriter(); $writer->openURI(APPLICATION_PATH . '/sitemap.xml'); // document head $writer->startDocument('1.0', 'UTF-8'); $writer->setIndent(4); $writer->startElement('urlset'); $writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); // Write something // this will write: <url><loc>some url here; SO not allowed me</loc></url> $writer->startElement('url'); $writer->writeElement('loc', 'some

C# Parallel library, XmlReader, XmlWriter

只愿长相守 提交于 2019-12-04 13:06:30
问题 I have a use case where I need to: iterate through each Input node in an Xml document perform a time-intensive calculation on each Input, and write the results to an XML file. Input looks something like this: <Root> <Input> <Case>ABC123</Case> <State>MA</State> <Investor>Goldman</Investor> </Input> <Input> <Case>BCD234</Case> <State>CA</State> <Investor>Goldman</Investor> </Input> </Root> and the output: <Results> <Output> <Case>ABC123</Case> <State>MA</State> <Investor>Goldman</Investor>