Elements / Island XmlDocument does not have a constructor?

Hello,

I use XML documents quite often. The XMLDocument class in Elements / RTL does not seem to have a constructor. How do I go about creating a new XMLDocument?

Thank you,
Brian Wheatley

It has factory methods, because .ctors would have been to limited in regards to what overloads can handle (ie, would new XmlDocument(string) take a filename or an XML string?). Look for the static From* and TryFrom* methods.

If we ever add support for multiplee named .ctors with the same parameters, on .NET, I might add .ctors as well. (eg new XmlDocument withString(), new XmlDocument withFile(), etc).

I guess I’m not understanding. I want to create a completely new XML document if one does not exist.

For example, how do I do the equivalent of:

XMLDocumet document = new XMLDocument();

if (file.exists(filename))
  document.Load(filename);

// read / edit the document

document.Save(filename);

Do I pass an empty string to the From* and TryFrom* methods?
Do I have to pass it a string, such as XMLDocument document = XMLDocument.From("<?xml version="1.0" ?>")?

Well, an “empty” xml document would be invalid, you gotta start with something. So either WithRootElement ir FromString can work, depending on what’s more convenient; WithRootElement can take an XmlElement instance or just a name for the root element.