Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XmlElements won't write on a new line.

XmlElements won't write on a new line.

Scheduled Pinned Locked Moved XML / XSL
questiondata-structuresxmlhelp
2 Posts 2 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen Holdorf
    wrote on last edited by
    #1

    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
    
    M 1 Reply Last reply
    0
    • S Stephen Holdorf

      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
      
      M Offline
      M Offline
      Maciej Los
      wrote on last edited by
      #2

      Doesn't matter if xml nodes are in the same line untill the xml is well formatted.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups