Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What are the different ways of writing xml values in C#

I am new to .xml files in general and I am currently working on project where I take simple .txt file with values inside of it and generating a .xml file out of it.

I am trying to replicate this in the xml file:
<value1 name="value2"/>
Only value2 gets changed based on the .txt file.

Using

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

xmlWriter.WriteStartElement() 

with

xmlWriter.WriteElementString() 

I am getting working files but the resulting .xml file looks different from what I want.

<value1 name="value2"> </value1>

>Solution :

Try this:

xmlWriter.writeStartElement("value1");
xmlWriter.writeAttributeString("name", "value2");
xmlWriter.writeEndElement();

also set:

XmlWriterSettings wSettings = new XmlWriterSettings();
wSettings.Indent = true;
wSettings.ConformanceLevel = ConformanceLevel.Fragment;
wSettings.OmitXmlDeclaration = true;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading