0

Take for example:

  • new XAttribute("Completed", true)
    
  • studentElement.SetAttributeValue("Included", studentItem.Type != string.Empty);
    

In both instances, the resulting XML file will have ether "true or "false". Is it possible to set up the XDocument so that all bool attribute values are saved as 0 and 1 respecively?

I know I can do:

  • new XAttribute("Completed", "1")
    
  • studentElement.SetAttributeValue("Included",
         studentItem.Type != string.Empty ? "1" : "0");
    

Is there a simple alternative?


I am using Load and Save to read / write to XML file (XDocument).

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 2
    [It doesn't look like it](https://source.dot.net/#System.Private.Xml/System/Xml/XmlConvert.cs,82c1e735c6f49e18) – canton7 Jan 10 '22 at 09:35
  • @canton7 Thanks for the link. Fair enough. Just wondered in the `XDocument` had some control over how they were written to / from the file. – Andrew Truckle Jan 10 '22 at 09:43
  • 2
    [This constructor](https://source.dot.net/#System.Private.Xml.Linq/System/Xml/Linq/XAttribute.cs,54) calls [this method](https://source.dot.net/#System.Private.Xml.Linq/System/Xml/Linq/XContainer.cs,4390095c431478d1), which unconditionally calls the other method I linked -- so there's no way to configure that call chain I'm afraid – canton7 Jan 10 '22 at 09:45

0 Answers0