xmlwriter

XmlWriter encoding issues

旧时模样 提交于 2019-12-04 12:21:27
问题 I have the following code: MemoryStream ms = new MemoryStream(); XmlWriter w = XmlWriter.Create(ms); w.WriteStartDocument(true); w.WriteStartElement("data"); w.WriteElementString("child", "myvalue"); w.WriteEndElement();//data w.Close(); ms.Close(); string test = UTF8Encoding.UTF8.GetString(ms.ToArray()); The XML is generated correctly; however, my problem is the first character of the string 'test' is ï (char #239), making it invalid to some xml parsers: where is this coming from? What

Writing formatted XML with XmlWriter

青春壹個敷衍的年華 提交于 2019-12-04 02:47:09
问题 I'm trying to write to an XML file to the isolated storage but I would like to format it like this:- <SampleData> <Item Property1="AliquaXX" /> <Item Property1="Integer" /> <Item Property1="Quisque" /> <Item Property1="Aenean" /> <Item Property1="Mauris" /> <Item Property1="Vivamus" /> <Item Property1="Nullam" /> <Item Property1="Nam" /> <Item Property1="Sed" /> <Item Property1="Class" /> </SampleData> but I'm buggered if I can work it out, can anyone help? 回答1: You can customize the xml

XMLWriter: WriteStartElement with a tag name and string to indicate tag name

大憨熊 提交于 2019-12-03 22:12:44
问题 I have same tag names and different strings to different the tag name. here is the XML. <order> <ID>1001</ID> <config> <properties> <entry key="Total">10</entry> <entry key="Name">name</entry> <entry key="Config">COMMON</entry> <entry key="Delivery">15-FEBRUARY-2013</entry> <entry key="Setting">name</entry> </properties> <id>19</id> </config> <aID>58239346</aID> </order> here is my current code: public String cards(string id) { StringWriter str = new StringWriter(); XmlTextWriter xmlWriter =

How to write XML files?

亡梦爱人 提交于 2019-12-03 09:06:16
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. Shameless self-promotion: KSXMLWriter codelark 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 decisions here on his blog. Try the open source XML stream writer for iOS : Written in Objective-C, a single .h

XmlWriter encoding issues

久未见 提交于 2019-12-03 07:50:01
I have the following code: MemoryStream ms = new MemoryStream(); XmlWriter w = XmlWriter.Create(ms); w.WriteStartDocument(true); w.WriteStartElement("data"); w.WriteElementString("child", "myvalue"); w.WriteEndElement();//data w.Close(); ms.Close(); string test = UTF8Encoding.UTF8.GetString(ms.ToArray()); The XML is generated correctly; however, my problem is the first character of the string 'test' is ï (char #239), making it invalid to some xml parsers: where is this coming from? What exactly am I doing incorrectly? I know I can resolve the issue by just starting after the first character,

java.net.SocketException: Network is unreachable: connect

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to download a xml text file from a web server using this method: static void download (String url , String fileName) throws IOException{ FileWriter xmlWriter; xmlWriter = new FileWriter(fileName); System.out.println("URL to download is : " + url); // here Exception is thrown///////////////////////////////// BufferedReader inputTxtReader = new BufferedReader (new BufferedReader(new InputStreamReader(addURL.openStream()))); //////////////////////////////////////////////////////// String str ; String fileInStr = ""; str =

XmlSerializer change encoding

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using this code to Serialize XML to String : XmlWriterSettings xmlWriterSettings = new XmlWriterSettings { indent = true, Encoding = Encoding.UTF8 }; using (var sw = new StringWriter()) { using (XmlWriter xmlWriter = XmlWriter.Create(sw, xmlWriterSettings)) { XmlSerializer xmlSerializer = new XmlSerializer(moviesObject.GetType(), new XmlRootAttribute("category")); xmlSerializer.Serialize(xmlWriter, moviesObject); } return sw.ToString(); } The problem is that i get : <?xml version="1.0" encoding="utf-16"?> <category xmlns:xsi="http://www

Multidimensional array iteration

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Say you have the following array: $nodes = array( "parent node", "parent node", array( "child node", "child node", array( "grand child node", "grand child node"))); How would you go about transforming it to an XML string so that it looks like: parent node parent node child node child node grand child node grand child node One way to do it would be through a recursive method like: function traverse($nodes) { echo " "; foreach($nodes as $node) { if(is_array($node)) { traverse($node); } else { echo " $node "; } } echo " "; } traverse($nodes); I

Dom4j解析XML

匿名 (未验证) 提交于 2019-12-02 23:49:02
1.Dom4j简介:           创建xml文件: <?xml version="1.0" encoding="UTF-8"?> <phoneInfo> <brand name="小米"> <type name="小米8"/> <type name="小米9"/> <type name="小米MIX"/> </brand> <brand name="iPhone"> <type name="iPhone9"/> <type name="iPhoneX"/> <type name="iPhoneXS"/> </brand> <brand name="华为"> <type name="P20"/> <type name="P30"/> <type name="P30 pro"/> </brand> </phoneInfo> info.xml  xml解析――查询 1 package cn.kgc.dom4jtest; 2 3 import org.dom4j.Document; 4 import org.dom4j.Element; 5 import org.dom4j.io.SAXReader; 6 7 import java.util.Iterator; 8 9 /** 10 * xml 解析 11 */ 12 public class Test { 13 public

php XML export issue with XMLWriter using writeAttribute() method

为君一笑 提交于 2019-12-02 13:03:32
问题 I am exporting a table data into xml which contains multilingual content in content column with mix of html e.g $xmlWriter->writeAttribute('value', $contents); record: name="testing" , contents="Just <span style="color:red">testing</span>:漢字" Exported as: <entry key="testing" value="Just <span style='color:red'>testing</span>:漢字"> Expected: <entry key="testing" value="Just <span style='color:red'>testing</span>:漢字"> I dont want xml writer to encode the multilingual characters , how this is