xmlwriter

Proper name space managment in .NET XmlWriter

I use .NET XML technologies quite extensively on my work. One of the things the I like very much is the XSLT engine, more precisely the extensibility of it. However there one little piece which keeps being a source of annoyance. Nothing major or something we can't live with but it is preventing us from producing the beautiful XML we woul...

Are there any resources about the PHP XMLWriter functionality?

The PHP documentation can be found here, but I think it's rather lacking. There are no examples of how to use these functions, and few (if any) of the pages have user comments. So where might I be able to find an explanation (and example code) on how to use these functions to write an XML document? ...

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

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 Strin...

What's the best way to synchronize XmlWriter access to a file to prevent IOExceptions?

There are multiple places in an application which call XmlWriter.Create on the same file, all accessed through the following function. When one calls while another is still writing, I get an IOException. What's the best way to lock or synchronize access? Here's the function that's being used: public void SaveToDisk() { ...

Creating an XML Element object from an XML Writer in C#

I'm writing a Windows service in C#. I've got an XmlWriter which is contains the output of an XSLT transformation. I need to get the XML into an XMLElement object to pass to a web service. What is the best way to do this? ...

XmlWriter only escaping one kind of quote

Here's some C# code: var sb = new StringBuilder(); var w = XmlWriter.Create(sb); w.WriteStartElement("hello"); w.WriteAttributeString("target", "world ' \" !"); w.WriteEndElement(); w.Flush(); // then look at sb.ToString() I'm getting a string that looks like: <?xml version="1.0" encoding="utf-16"?><hello target="world ' &quot; !" /...

Possible to write XML to memory with XmlWriter?

I am creating an ASHX that returns XML however it expects a path when I do XmlWriter writer = XmlWriter.Create(returnXML, settings) But returnXML is just an empty string right now (guess that won't work), however I need to write the XML to something that I can then send as the response text. I tried XmlDocument but it gave me an erro...

EventBinding in a codebehind generated DataTemplate

Hi there, lets begin with the scenario: I have an ItemsControl inside a UserControl. In this ItemsControl I have a dynamicly created DataTemplate which is created and added in codebehind. As there doesn't seem to be a nice way to create a DataTemplate in codebehind I had to programmatically generate the xaml code for my DataTemplate in...

Where to write XML with XmlWriter for sending via HttpWebRequest POST in ASP.NET?

Here is my code, see the part that says ???WHAT TO DO HERE??? I am not sure where I write this XML to in order to be able to send it in my POST via the objRequest there... string project_id = context.Request.QueryString["project"]; string person_id = context.Request.QueryString["person"]; string post_date = context.Request.QueryString["...

XmlWriter encoding issues

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.ToA...

output xml with attributes

Hello, How do I get this output? <MSRP currency="USD">10.00</MSRP> writer.WriteElementString("MSRP", Convert.ToString(q.ItemPrice1)); writer.WriteAttributeString("currency", "MSRP", "USD"); this is the error: Token StartAttribute in state Content would result in an invalid XML document. ...

Tracking namespace declarations with XMLWriter

Hi, I'm working on an XML webservice (in PHP!), and in order to do things 'right', I want to use XMLWriter instead of just concatinating strings and hoping for the best. I'm using XML namespaces everywhere using ->startElementNS and ->writeElementNS. The problem, is that every time I use these functions a new namespace declaration is a...

VB.NET XMLWriter: How to change what's in the header?

I have a requirement to make an XML file - and the partner is rather sticky about the header. Apparently, the header must be exactly this: <?xml version="1.0"?> But whenever I create an XML file I get extraneous properties like this: <?xml version="1.0" encoding="utf-8" standalone="yes"?> The hacker in me wants to stop using XMLWr...

How to format an XML with closing nodes and tags on a new line?

I'm modifying some .vcrpoj files in .NET but when I save them the formatting changes (which wrecks havoc with my diff tool), the original files look like this: <VisualStudioProject ProjectType="Visual C++" Version="8.00" > <Platforms> <Platform Name="Win32" /> </Platforms> <ToolFiles> </ToolFiles> But when I save the changes it lo...

How to create a XmlDocument using XmlWriter in .NET?

Many .NET functions use XmlWriter to output/generate xml. Outputting to a file/string/memory is a very operation: XmlWriter xw = XmlWriter.Create(PutYourStreamFileWriterEtcHere); xw.WriteStartElement("root"); ... Sometimes , you need to manipulate the resulting Xml and would therefore like to load it into a XmlDocument or might need a...

Are XmlMtomReader and XmlMtomWriter fully implemented in Mono project?

I'm working on a cross-platform solution currently. The solution uses XmlMtomReader and XmlMtomWriter from .NET framework 3.0. Now i need to know if these two classes (and all the nessasary infrastructure around them) are fully supported in Mono project from the porting-it-to-linux point of view. :) ...

How do you get an XmlWriter to write an HTML tag with xmlns and xml:lang?

I am using an XmlWriter to render HTML. How can I get an XmlWriter to emit a proper tag that looks like this? <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> here is what I have so far var xml = XmlWriter.Create(HtmlFileName, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true}); xml.WriteDocType("html...

XmlWriter Not Creating New Element in VB.net

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...

How can i remove BOM from XmlTextWriter using C#

Hi, i need to remove the BOM from an XML file that is being created. I have tried using the new UTF8Encoding(false) method but it doesnt work. Here is the code i have: XmlDocument xmlDoc = new XmlDocument(); XmlTextWriter xmlWriter = new XmlTextWriter(filename, new UTF8Encoding(false)); xmlWriter.Formatting = Formatting....

XMLWriter for HTML creation - how to add simple non-pair tags?

Hi, I was advised to use XMLwriter to build HTML documents in order to display them in webbrowser object. Creating doctype and startelements like HTML,BODY is OK..but I am experiencing 2 main problems: I cannot add tags like <br>. Using WriteString skips < and >. The output string is one line - I would need something like writeLine. Yo...