1
How to append the standalone directive to generated xml
Question asked by Goos van Beek - 4/17/2021 at 10:30 AM
Answered
I generate c# code based on a xsd schema. I want to use the directive standalone in the generated xml. 
How can I append this?
<?xml version="1.0" encoding="utf-8" standalone="yes"?>

4 Replies

Reply to Thread
0
Liquid Support Replied
Employee Post
Hi,

Which tool are you using to generate the C#?
- Liquid Data Mapper, Liquid XML Objects or Liquid XML Data Binder?
0
Goos van Beek Replied
I'm using Liquid XML Data Binder.
0
Liquid Support Replied
Employee Post Marked As Answer
I would suggest moving to the new Liquid XML Objects code generator for C#, this has more flexibility as you can use your own .Net XmlWriter to write whatever you require.

But you can also achieve this with Liquid XML Data Binder as follows...

Using the Default context:
// add custom value to ProcessingInstructions collection in Default context
SerializationContext.Default.ProcessingInstructions.Add("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");

// set includeDocHeader = false in ToXml
string strXml = elm.ToXml(false, System.Xml.Formatting.Indented, EOLType.CRLF);
Using a Custom Context:
// add custom value to ProcessingInstructions collection in custom context
SerializationContext context = new SerializationContext();
context.ProcessingInstructions.Add("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");

// set includeDocHeader = false in ToXml
string strXml = elm.ToXml(false, System.Xml.Formatting.Indented, EOLType.CRLF, context);

0
Goos van Beek Replied
Thanks for your suggestions, I'll give it a try!

Regards,
Goos van Beek.

Reply to Thread