Open wujwmail opened 1 month ago
using System;
using Pchp.Core;
using Peachpie.Library.XmlDom;
......
static void Main(string[] args)
{
Context ctx = Context.CreateConsole(null, args);
XMLWriter xw = new XMLWriter();
xw.openMemory(ctx);
xw.startElement("element");
xw.writeAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/content-types");
// xw.writeAttribute("not_xmlns", "http://schemas.openxmlformats.org/package/2006/content-types");
xw.endElement();
Console.WriteLine(xw.flush());
Console.ReadLine();
}
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
using (var writer = System.Xml.XmlWriter.Create(Console.Out, settings))
{
writer.WriteStartElement("element", "http://schemas.openxmlformats.org/package/2006/content-types");
// Write other elements and attributes
writer.WriteAttributeString("other", "123");
writer.WriteEndElement();
}
<element other="123" xmlns="http://schemas.openxmlformats.org/package/2006/content-types" />
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Items");
writer.WriteAttributeString("xmlns", "http://schemas.openxmlformats.org/package/2006/content-types");
writer.WriteEndElement();
writer.Close();
XmlTextWriter
seems to work ok.
Do you think it's compatible with XmlWriter
?
XmlTextWriter inherits from XmlWriter and can be replaced by XmlTextWriter. However, there is a small problem that the XmlWriterSettings class cannot be injected. Let me try and see if there is a way to solve it?
I see! the missing XmlSettings might be a problem :/
This problem has been solved using XmlTextWriter! For details, see: https://github.com/peachpiecompiler/peachpie/pull/1140
Running error message:
PHPExcel source code (PHPExcel-1.8.1): https://github.com/PHPOffice/PHPExcel
\PHPExcelPhpCsLib\PHPExcel\Writer\Excel2007\ContentTypes.php:line 61 This statement seems to be wrong:
demo download -> https://github.com/wujwmail/PHPExcel_test/tree/master
A php example for testing writeAttribute