0

I am having a below xml data created by c# code which is not in my required format. Can any one suggest how to get this done ?

C# Code for this:

            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Encoding = Encoding.UTF8;

            using (XmlWriter writer = XmlWriter.Create("SNP.xml",xmlWriterSettings))
            {                    
                writer.WriteStartDocument();
                writer.WriteStartElement("Request","http://www.ABC.com/submit");

                foreach (DataRow row in ExcelData.Rows)
                {
                    writer.WriteStartElement(ExcelData.Rows[counter]["MyDATA"].ToString());


                    writer.WriteElementString("DATA1", ExcelData.Rows[counter]["DATA1"].ToString());
                    writer.WriteElementString("DATA2", ExcelData.Rows[counter]["DATA2"].ToString());

                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

Data generated by c#:

<?xml version="1.0" encoding="utf-8" ?> 
  - <Request xmlns="http://www.timvw.be/ns">
- <MyData>
  <DATA1>91.689117127891</DATA1> 
  <DATA2>0.18242169290979</DATA2> 
  </MyData>  
  </Request>

however i need the xml data in below format:

  <?xml version="1.0" encoding="utf-16" ?> 
- <Request xmlns="http://www.ABC.com/submit" xmlns:l="http://www.ABC.com/link" l:source="SRC" l:date="2014-03-05">
- <MyData l:identifier="PRAV" l:value="151.19448366182007269092408546">
  <DATA1 l:value="0.151328110447635" /> 
  <DATA2 l:value="0.6461191930062688087600920641" /> 
  <DATA3 l:value="0.144793773777417" /> 
  </MyData>
  </Request>

Can any one suggest what needs to be set to in c# code to get

1 Answer 1

1

If you need to write the values as an XmlAttribute, try this:

writer.WriteStartElement("DATA1");
writer.WriteAttributeString("l:value", ExcelData.Rows[counter]["DATA1"].ToString());
writer.WriteEndElement();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.