Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 993527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:26:15+00:00 2026-05-16T06:26:15+00:00

I like to create xml using the following formatting: XDocument xml = new XDocument(

  • 0

I like to create xml using the following formatting:

XDocument xml = new XDocument(
   new XElement("Root",
      new XElement("A",
         new XAttribute("X", xValue),
         new XAttribute("Y", yValue)),
      new XElement("B",
         new XAttribute("Z", zValue)),
      new XElement("C")));

It seems easy to read and kinda flows like a tabbed XML document (in my opinion). StyleCop is very unhappy with the formatting though. I get a lot of these errors:

SA1116: If the method parameters are on separate lines, the first parameter must begin on the line beneath the name of the method.

SA1118: The parameter spans multiple lines. If the parameter is short, place the entire parameter on a single line. Otherwise, save the contents of the parameter in a temporary variable and pass the temporary variable as a parameter.

What can i do to keep StyleCop happy and the code readable? I know i can disable the StyleCop rules, but the team would like to keep those rules for all the non XML creation code. I can selectively suppress the rule in every method that creates XML in this way, but that seems like a pain and gets to be ugly. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:26:16+00:00Added an answer on May 16, 2026 at 6:26 am

    Yes, I would suggest the following:

    • Create ‘default resources’ for your project (right-click the project, Properties, Resourced)
    • Create a new string resource there, set the Name as DefaultXmlDoc or something
    • Set the value as the following text:

      <Root>
      <A X="1" Y="2" />
      <B Z="3" />
      <C />
      </Root>
    • Change your program to the following one-liner:

      XDocument xml = XDocument.Parse( Properties.Resources.DefaultXmlDoc );

    I believe this accomplishes all your goals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT * FROM sys.tables WHERE TableName LIKE '%customer%' AND TableName… May 16, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer This is actually possible but it depends on what you… May 16, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer I very much doubt there is a compiler or interpreter… May 16, 2026 at 4:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using the new System.Xml.Linq to create HTML documents (Yes, I know about HtmlDocument,
I am trying to create hyperlinks using XML information and XSLT templates. Here is
I am looking to create an expression tree by parsing xml using C#. The
I am using XmlReader.Create to retrieve data from an RSS xml file. Then I
I'm working with a XML structure that looks like this: <ROOT> <ELEM_A> <A_DATE>20100825</A_DATE> <A_TIME>141500</A_TIME>
I am trying to create an XML file to conform to someones XSD this
I have the following xml <AAA> <BBB>Total</BBB> </AAA> Transforming it with the following xslt
Hi I'm using a class to parse my XML. I have to parse request
Been using XML for ages now for data storage & transfer, but have never
I'm trying to create an XML output file to import into another program. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.