XmlElements won't write on a new line.
-
I am using XmlElements and AppendChild to create an XML tree. Now, the first level from the root writes on a new line but all other XmlElements write on the same line. How do I get each new XmlElement to write on a new line with proper indentation? My code:
XmlAttribute ApplicantAttribute = doc.CreateAttribute("UserId");
ApplicantAttribute.Value = NumberGenerator(100000, 999999, 6);
Applicant.Attributes.Append(ApplicantAttribute);XmlNode ssnNameNode = doc.CreateElement("SSN"); ssnNameNode.AppendChild(doc.CreateTextNode(NumberGenerator(0, 999999999, 9))); Applicant.AppendChild(ssnNameNode); XmlNode aNameNode = doc.CreateElement("Name"); aNameNode.AppendChild(doc.CreateTextNode("Place Holdor Name")); Applicant.AppendChild(aNameNode); XmlNode demDataNode = doc.CreateElement("DemographicData"); demDataNode.AppendChild(doc.CreateTextNode("DemographicData")); aNameNode.AppendChild(demDataNode); XmlNode FullName = doc.CreateElement("FullName"); FullName.AppendChild(doc.CreateTextNode("FullName")); demDataNode.AppendChild(FullName); XmlNode LegalName = doc.CreateElement("LegalName"); LegalName.AppendChild(doc.CreateTextNode("LegalName")); FullName.AppendChild(LegalName); XmlNode Last = doc.CreateElement("Last"); Last.AppendChild(doc.CreateTextNode("Last")); LegalName.AppendChild(Last); XmlNode First = doc.CreateElement("First"); First.AppendChild(doc.CreateTextNode("First")); LegalName.AppendChild(First); Applicant.AppendChild(demDataNode); RequestNode.AppendChild(Applicant);
The problem is that the output writes the following Xml file:
811163249 Place Holdor Name DemographicDataFullNameLegalNameLastFirst
-
I am using XmlElements and AppendChild to create an XML tree. Now, the first level from the root writes on a new line but all other XmlElements write on the same line. How do I get each new XmlElement to write on a new line with proper indentation? My code:
XmlAttribute ApplicantAttribute = doc.CreateAttribute("UserId");
ApplicantAttribute.Value = NumberGenerator(100000, 999999, 6);
Applicant.Attributes.Append(ApplicantAttribute);XmlNode ssnNameNode = doc.CreateElement("SSN"); ssnNameNode.AppendChild(doc.CreateTextNode(NumberGenerator(0, 999999999, 9))); Applicant.AppendChild(ssnNameNode); XmlNode aNameNode = doc.CreateElement("Name"); aNameNode.AppendChild(doc.CreateTextNode("Place Holdor Name")); Applicant.AppendChild(aNameNode); XmlNode demDataNode = doc.CreateElement("DemographicData"); demDataNode.AppendChild(doc.CreateTextNode("DemographicData")); aNameNode.AppendChild(demDataNode); XmlNode FullName = doc.CreateElement("FullName"); FullName.AppendChild(doc.CreateTextNode("FullName")); demDataNode.AppendChild(FullName); XmlNode LegalName = doc.CreateElement("LegalName"); LegalName.AppendChild(doc.CreateTextNode("LegalName")); FullName.AppendChild(LegalName); XmlNode Last = doc.CreateElement("Last"); Last.AppendChild(doc.CreateTextNode("Last")); LegalName.AppendChild(Last); XmlNode First = doc.CreateElement("First"); First.AppendChild(doc.CreateTextNode("First")); LegalName.AppendChild(First); Applicant.AppendChild(demDataNode); RequestNode.AppendChild(Applicant);
The problem is that the output writes the following Xml file:
811163249 Place Holdor Name DemographicDataFullNameLegalNameLastFirst
Doesn't matter if xml nodes are in the same line untill the xml is well formatted.