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 6236825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:54:51+00:00 2026-05-24T10:54:51+00:00

Possible Duplicate: XML attribute vs XML element I often tend to create xml out

  • 0

Possible Duplicate:
XML attribute vs XML element

I often tend to create xml out of my c# and php objects with their properties and their data to be able to store the data and structure in files, databases and to be able to port it to other systems.

My question is what the pros and cons are (if any) using an element structure or attribute structure.

Element structure

<Body>
  <Row Name="Gender">
    <Col>
      <Key>FieldId</Key>
      <Value>1</Value>
    </Col>
    <Col>
      <Key>ParentId</Key>
      <Value></Value>
    </Col>
  </Row>
  <Row Name="Weight">
    <Col>
      <Key>FieldId</Key>
      <Value>3</Value>
    </Col>
    <Col>
      <Key>ParentId</Key>
      <Value></Value>
    </Col>
  </Row>
</Body>

Attribute structure

<Body>
  <Row Name="Gender">
    <Col Key="FieldId" Value="1" />
    <Col Key="ParentId" Value="0" />
  </Row>
  <Row Name="Weight">
    <Col Key="FieldId" Value="2" />
    <Col Key="ParentId" Value="0" />
  </Row>
</Body>

Any recommendations and advices are welcome!

  • 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-24T10:54:51+00:00Added an answer on May 24, 2026 at 10:54 am

    I generally prefer a hybrid style, where the “main content” for each element is the text node. In your example, “Value” is clearly the main content, so I would use:

    <Body>
      <Row Name="Gender">
        <Col Key="FieldId">1</Col>
        <Col Key="ParentId">0</Col>
      </Row>
      <Row Name="Weight">
        <Col Key="FieldId">2</Col>
        <Col Key="ParentId">0</Col>
      </Row>
    </Body>
    

    My main argument for this style is that it combines legibility with support for a wide variety of content / values: Attribute style frequently chokes on line-breaks in content (eg MSXML and .Net will parse correctly but normalize the attribute content when you output the source Xml again), so if you want to preserve text formatting, an attribute-centric style is generally a bad choice.

    In the comment-linked question XML attribute vs XML element, several people describe it as a “data vs meta-data” question, which I think sums it up nicely. Data in elements, meta-data in attributes.

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

Sidebar

Related Questions

Possible Duplicate: Best XML Parser for PHP I have a string with XML data
Possible Duplicate: XML attribute vs XML element Can someone explain me why more and
Possible Duplicate: XML attribute vs XML element What is the difference between snippet A:
Possible Duplicate: How to extract a node attribute from XML using PHP's DOM Parser
Possible Duplicate: Regex Remove Images with style tag from Html PHP XML remove element
Possible Duplicate: How to parse and process HTML/XML with PHP? I want to grab
Possible Duplicate: Why am I getting an “Out of memory” error with Perl's XML::Simple?
Possible Duplicate: How do I remove a node element by id in XML? XML
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some
Possible Duplicate: Simple and clean xml manipulation in PHP I trying to reference specific

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.