xmlwriter

How to put an encoding attribute to xml other that utf-16 with XmlWriter?

北战南征 提交于 2019-11-27 07:57:44
I've got a function creating some XmlDocument: public string CreateOutputXmlString(ICollection<Field> fields) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = Encoding.GetEncoding("windows-1250"); StringBuilder builder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(builder, settings); writer.WriteStartDocument(); writer.WriteStartElement("data"); foreach (Field field in fields) { writer.WriteStartElement("item"); writer.WriteAttributeString("name", field.Id); writer.WriteAttributeString("value", field.Value); writer.WriteEndElement

Replacing the innertext of an Xml node/element

≡放荡痞女 提交于 2019-11-27 07:40:40
问题 First of all this is C#. I am creating a internet dashboard for a small group of colleages in the NHS. Below is an example xml file in which I need to change the innertext of. I need to replace a specific element for example "Workshop1." Because we have a few workshops I cannot afford to use a general writer because it will replace all the information on the XML document with this one bit of code below. <?xml version="1.0" ?> <buttons> <workshop1>hello</workshop1> <url1>www.google.co.uk</url1

使用DOM4J操作XML文件

半城伤御伤魂 提交于 2019-11-27 04:19:23
1. Dom4j 介绍 Dom4j是开放源代码的解析XML文件的框架,它拥有本地的XPath支持,但是不支持使用XPath选择节点 虽然 DOM4J 代表了完全独立的开发结果,但最初,它是JDOM 的一种智能分支。 它合并了许多超出基本 XML文档表示的功能,包括集成的 XPath支持、XML Schema 支持 以及用于大文档或流化文档的基于事件的处理。它还提供了构建文档表示的选项,它通过 DOM4J API 和标准 DOM 接口具有并行访问功能。 从2000下半年开始,它就一直处于开发 之中。 为支持所有这些功能,DOM4J 使用接口和抽象基本类方法。DOM4J 大量使用了 API 中的 Collections 类,但是在许多情况下,它还提供一些替代方法以允许更好的性能或更直 接的编码方法。 直接好处是,虽然 DOM4J 付出了更复杂的 API 的代价,但是它提供了比JDOM 大得多的灵活性。 在添加灵活性、XPath 集成和对大文档处理的目标时,DOM4J 的目标与 JDOM 是一样 的:针对 Java 开发者的易用性和直观操作。它还致力于成为比 JDOM 更完整的解决方案, 实现在本质上处理所有Java/XML问题的目标。在完成该目标时, 它比JDOM 更少强调防止 不正确的应用程序行为。 DOM4J 是一个非常非常优秀的Java XML API,具有性能优异

Indentation and new line command for XMLwriter in C#

不问归期 提交于 2019-11-27 02:09:37
问题 I am writing some data to XML file...but when I open it all the values are in a single line...how can write it in readable format?ie each node in new line and indentation? FileStream fs = new FileStream("myfile.xml", FileMode.Create); XmlWriter w = XmlWriter.Create(fs); w.WriteStartDocument(); w.WriteStartElement("myfile"); w.WriteElementString("id", id.Text); w.WriteElementString("date", dateTimePicker1.Text); w.WriteElementString("version", ver.Text); w.WriteEndElement(); w.WriteEndDocument

Can we force XmlWriter to issue <my-tag></my-tag> rather than <my-tag/>?

南楼画角 提交于 2019-11-26 23:19:13
问题 By default, someXmlWriter.WriteElementString("my-tag", someString); produces <my-tag /> I looked around XmlWriterSettings class for possible options that would force the writer to produce <my-tag></my-tag> instead but didn't find anything. Is there a simple way of forcing the XmlWriter to issuing empty elements with "open tag, close tag" rather than with the short-hand form? Edit : Yes! I realize that with regards to XML validity the two notations are equivalent, valid and all... I'm however

How to put an encoding attribute to xml other that utf-16 with XmlWriter?

我们两清 提交于 2019-11-26 17:44:17
问题 I've got a function creating some XmlDocument: public string CreateOutputXmlString(ICollection<Field> fields) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.Encoding = Encoding.GetEncoding("windows-1250"); StringBuilder builder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(builder, settings); writer.WriteStartDocument(); writer.WriteStartElement("data"); foreach (Field field in fields) { writer.WriteStartElement("item"); writer

Appending an existing XML file with XmlWriter

亡梦爱人 提交于 2019-11-26 15:31:30
I've used the following code to create an XML file: XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.NewLineOnAttributes = true; using (XmlWriter xmlWriter = XmlWriter.Create("Test.xml", xmlWriterSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("School"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } I need to insert nodes dynamically creating the following structure: <?xml version="1.0" encoding="utf-8"?> <School /> <Student> <FirstName>David</FirstName> <LastName>Smith<

Create XML in Javascript

纵饮孤独 提交于 2019-11-26 10:36:19
问题 I\'m wondering, is it possible to create an XML file with some data in Javascript? I have the data stored in variables. I\'ve googled around a bit and it doesn\'t seem like it\'s talked about much. I thought i could use XMLWriter such as this: var XML = new XMLWriter(); XML.BeginNode (\"testing\"); XML.Node(\"testingOne\"); XML.Node(\"TestingTwo\"); XML.Node(\"TestingThree\"); XML.EndNode(); as stated in this tutorial:EHow Tutorial However, when i execute this code i get the following error:

Appending an existing XML file with XmlWriter

霸气de小男生 提交于 2019-11-26 04:00:04
问题 I\'ve used the following code to create an XML file: XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.NewLineOnAttributes = true; using (XmlWriter xmlWriter = XmlWriter.Create(\"Test.xml\", xmlWriterSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement(\"School\"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } I need to insert nodes dynamically creating the following structure