xmlwriter

Can one force XMLWriter to write elements in single quotes?

寵の児 提交于 2019-12-10 20:07:06
问题 Here's my code: var ptFirstName = tboxFirstName.Text; writer.WriteAttributeString("first",ptFirstName); note that ptFirstName will end up in double quotes even if I use ptFirstName = ptFirstName.Replace("\"","'"); This does not work either since the writer will still force double quotes in my file as follows: when in fact I need (don't ask me why - it's a long story...) 回答1: Yes, you can set what character is used for quotes by setting the XmlTextWriter.QuoteChar property. See http://msdn

XML WriteAttributeString error

孤人 提交于 2019-12-10 16:17:50
问题 When I write this entry here: <XmlRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nsSBAK" xsi:schemaLocation ="urn:nsSBAK SBAK.xsd"> with this code: xmlWriter.WriteStartElement("XmlRoot"); xmlWriter.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); xmlWriter.WriteAttributeString("xmlns", null, null, "urn:nsSBAK"); xmlWriter.WriteAttributeString("schemaLocation", null, "urn:nsSBAK SBAK.xsd"); I get debug error: The prefix '' cannot

output or write to a xml file?

淺唱寂寞╮ 提交于 2019-12-10 11:44:22
问题 $fp = fopen('data.txt', 'r'); $xml = new SimpleXMLElement('<allproperty></allproperty>'); while ($line = fgetcsv($fp)) { if (count($line) < 4) continue; // skip lines that aren't full $node = $xml->addChild('aproperty'); $node->addChild('postcode', $line[0]); $node->addChild('price', $line[1]); $node->addChild('imagefilename', $line[2]); $node->addChild('visits', $line[3]); } echo $xml->saveXML(); im using this script to convert text file into a xml file, but i want to output it to a file,

How to check name of element with WriteEndElement

与世无争的帅哥 提交于 2019-12-09 17:17:59
问题 I'm writing xml with XmlWriter. My code has lots of sections like this: xml.WriteStartElement("payload"); ThirdPartyLibrary.Serialise(results, xml); xml.WriteEndElement(); // </payload> The problem is that the ThirdPartyLibrary.Serialise method is unreliable. It can happen (depending on the variable results ) that it doesn't close all the tags it opens. As a consequence, my WriteEndElement line is perverted, consumed closing the library's hanging tags, rather than writing </payload> . Thus I

string escape into XML-Attribute

杀马特。学长 韩版系。学妹 提交于 2019-12-09 15:39:41
问题 I had a look at string escape into XML and found it very useful. I would like to do a similar thing: Escape a string to be used in an XML-Attribute. The string may contain \r\n. The XmlWriter class produces something like \r\n -> The solution I'm currently using includes the XmlWriter and a StringBuilder and is rather ugly. Any hints? Edit1: Sorry to disappoint LarsH, buy my first approach was public static string XmlEscapeAttribute(string unescaped) { XmlDocument doc = new XmlDocument();

How to write XML files?

荒凉一梦 提交于 2019-12-09 06:22:08
问题 I want to write a not so complicated but large file within my app and be able to send it by mail (using MFMailComposeViewController) Since NSXMLElement and related classes are not ported to iPhone SDK what options do I have for creating XML documents? Thanks in advance. 回答1: Shameless self-promotion: KSXMLWriter 回答2: I would recommend using KissXML. The author started in a similar situation as you and created an NSXML compatible API wrapper around libxml. He discusses the options and

Import XML file into PostgreSQL Database

醉酒当歌 提交于 2019-12-08 05:38:30
问题 A few days ago I managed it to export 3 different PgSQL tables into one XML file. Now, I'd like to import the Same file. I've searched for about 2 hours but only found solutions for Importing a XML into one Table. Here ist the structure of the XML <?xml version="1.0" encoding="UTF-8"?> <Table1 Col1="xxx" Col2="xxx"> <Table2 Col1="xxx"> <Table3 Col1="xxx" Col2="xxx" Coln="xxx"/> </Table2> <Table2 Col1="xxx"/> <Table2 Col1="xxx"> <Table3 Col1="xxx" Col2="xxx" Coln="xxx"/> </Table2> </Table1>

Write XML directly to disk and append elements

不羁的心 提交于 2019-12-07 15:57:25
问题 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

XmlWriter encoding UTF-8 using StringWriter in C#

ⅰ亾dé卋堺 提交于 2019-12-07 06:28:39
问题 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

Return all attributes of an HtmlElement in Web browser

ⅰ亾dé卋堺 提交于 2019-12-07 01:58:36
问题 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")