xmlwriter

PHP XMLWriter, how to insert a line break?

此生再无相见时 提交于 2019-12-14 01:20:07
问题 I'm using XMLWriter http://www.php.net/manual/en/book.xmlwriter.php to let my webclient create an XML File. In the beginning there has to be an element with very many attributes, like this: $xml->startElement('registry-request'); $xml->writeAttribute('att1', 'long text'); $xml->writeAttribute('att2', 'long text'); $xml->writeAttribute('att3', 'long text'); $xml->writeAttribute('att4', 'long text'); So that part in the XML file will look something like this: <registry-request att1="long text"

Formatting string in XML format and remove invalid attribute characters

感情迁移 提交于 2019-12-13 08:28:11
问题 I've a string say "<Node a="<b>">" . I need to escape only the data and parse this string as a node in XMLWriter. Hence how to escape only the attribute value "<" and note the XML structure's "<". 回答1: using (var writer = XmlWriter.Create(Console.Out)) { writer.WriteStartElement("Node"); writer.WriteAttributeString("a", "<b>"); } Output <Node a="<b>" /> Firstly you should parse the string. Since this is not valid xml, you can't use an xml parser. You can try HtmlAgilityPack. Then you can

XmlWriter inserting spaces when xml:space=preserve

◇◆丶佛笑我妖孽 提交于 2019-12-12 09:45:33
问题 Given this code (C#, .NET 3.5 SP1): var doc = new XmlDocument(); doc.LoadXml("<?xml version=\"1.0\"?><root>" + "<value xml:space=\"preserve\">" + "<item>content</item>" + "<item>content</item>" + "</value></root>"); var text = new StringWriter(); var settings = new XmlWriterSettings() { Indent = true, CloseOutput = true }; using (var writer = XmlWriter.Create(text, settings)) { doc.DocumentElement.WriteTo(writer); } var xml = text.GetStringBuilder().ToString(); Assert.AreEqual("<?xml version=

XmlWriter The ':' character, hexadecimal value 0x3A, cannot be included in a name

微笑、不失礼 提交于 2019-12-12 02:07:13
问题 I am using an XmlWriter and getting the following error: Invalid name character in 'news:news'. The ':' character, hexadecimal value 0x3A, cannot be included in a name. does anyone have any idea what is causing this? here is my code: using (XmlWriter writer = XmlWriter.Create("moo.xml")) { writer.WriteStartDocument(); writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9"); writer.WriteAttributeString("xmlns", "news", null, "http://www.google.com/schemas/sitemap-news

Building an XML file iteratively with XmlWriter

馋奶兔 提交于 2019-12-11 13:59:22
问题 I want to be able to use XmlWriter (C#, .NET) to create an XML document with multiple calls to a method that generates XML and then a single call to a final method that closes everything off. When I try to call this method multiple times: private void SiblingGenerator(List<XmlNode> XMLList, XmlWriter textWriter, string newPath, FileInfo fi) { if (fi.Length == 0) { MessageBox.Show("file doesn't exist"); textWriter.WriteStartDocument(); textWriter.WriteStartElement("batch"); //... } // ... } ..

Create a XML File from a list based on a conditional

人盡茶涼 提交于 2019-12-11 12:16:27
问题 I've been trying to understand that for several hours but got no luck. I've a list based on a class: public class xmldata //Class to receive items list { public string xml_filename { get; set; } public string colorname { get; set; } public string colorvalues { get; set; } } Then i made a separated class to hold the list: public class xmldatalist { public List<xmldata> FullList = new List<xmldata>(); } Each position of this list (FullList) contains three elements from xmldata - the specific

Write to existing xml file without replacing it's contents (XmlWriter)

Deadly 提交于 2019-12-11 11:05:05
问题 I encountered following issue, I first write to my xml file like this: XmlTextWriter writer = new XmlTextWriter("course.xml", null); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("Course"); writer.WriteAttributeString("title", "Examle"); writer.WriteAttributeString("started", "true"); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); And xml output I get is: <?xml version="1.0"?> <Course title="Example" started="true" />

XmlWriter Not Creating New Element in VB.net

泪湿孤枕 提交于 2019-12-11 05:28:07
问题 I'm writing out an XML file using VB.net. When I try to create another element to be written past the first, it errors out saying: "Token StartElement in state EndRootElement would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment." I'm not sure why it is doing this considering that the previous element has been closed. I tried to look for a writer.WriteEndRootElement

Retain XML code when using PHP XMLWriter::writeElement

一个人想着一个人 提交于 2019-12-11 04:58:37
问题 I have a mySQL table with fields containing copy that's being turned into XML. Some of the copy in the mySQL fields has bold tags around the words: <b>This will be bold</b>, this won't be . However, when I come to build my XML document using XMLwriter, the copy ends up looking like this: <b>This will be bold</b>, this won't be Can anyone advise me on how I can avoid character encoding for these tags? 回答1: I am guessing your code needs to use XMLWriter::writeRaw instead of XMLWriter::text.

What am I doing wrong here, having issues with XSLT using C#

点点圈 提交于 2019-12-11 01:40:16
问题 Please take a look at the following code, as I get the error at this line: xslt.Transform(mydoc.CreateReader(), writer); Error: Step into: Stepping over non-user code 'System.Xml.Linq.XNode.CreateReader' A first chance exception of type 'System.NullReferenceException' occurred in System.Data.SqlXml.dll ((System.NullReferenceException)(ex)) PromotionsDataContext db = new PromotionsDataContext(); //XmlDocument myxml; XElement Categories = new XElement("Promotions", from b in db.GetPromotions()