Given the following XML structure:
<?xml version="1.0" encoding="utf-8"?>
<Persons>
<Person>
<Name>Person 1</Name>
<Age>30</Age>
</Person>
<Person>
<Name>Person 2</Name>
<Age>32</Age>
</Person>
</Persons>
I want to add Person to the collection, and I was hoping this could be done using the Xml TypeProvider API.
My approach is as follows:
type PersonXmlProvider = XmlProvider<""".\Persons.xml""">
let personsXml = PersonXmlProvider.GetSample()
personsXml.XElement.Add(new PersonXmlProvider.Person("Person 3", 33))
personsXml.XElement.Save("Persons.xml")
What happens:
A person is added to the xml collection and written to a file.
Unexpected:
But the encoding is incorrect, because the XML tags are encoded as <they were >instead of <and>.
What am I missing?
The documentation states that UTF-8 is the default.
Update
XML result
<?xml version="1.0" encoding="utf-8"?>
<Persons>
<Person>
<Name>Person 1</Name>
<Age>30</Age>
</Person>
<Person>
<Name>Person 2</Name>
<Age>32</Age>
</Person><Person>
<Name>Person 3</Name>
<Age>33</Age>
</Person>
</Persons>
source
share