Hi I have to save this file in xfdf file in C# using XmlWriter Class;
using (var fs = File.Open("D://abc.xfdf", FileMode.Create))
{
try
{
var doc = XmlWriter.Create(fs);
doc.WriteStartElement("Highlights");
foreach (var h in Highlights)
{
doc.WriteStartElement("Highlight");
doc.WriteElementString("Id", h.Id);
doc.WriteEndElement();
}
doc.WriteEndElement();
doc.Flush();
}
}
But I am not able save in xfdf file. getting problem to adding
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
Your link doesn't really explain what your problem is, but I'll take a sample bit of XML from there and walk you through creating it. The principles can be applied to whichever elements you're actually trying to create.
So, while you can do this with
XmlWriter
directly, this is generally not a good idea - it's very low level and as a result not very nice to read or write. For example, this is the code it would take to just create the outer element and the first child. Notice how you have to be very careful to match writing the start and end of elements:Alternatively, you can use the much higher level, cleaner LINQ to XML API to declaratively create your XML:
You can use the API to add elements from a sequence in a variety of different ways, such as:
Or:
As ever, Google is your friend. There are lots of examples on how to use LINQ to XML.