XML Structure

Discussion in 'XML' started by shapper, May 29, 2009.

  1. shapper

    shapper Guest

    Hello,

    I am replicating an SQL database table in XML. I have the following
    columns:

    public class Bag {
    public Guid Id { get; set; }
    public String Content { get; set; }
    public DateTime? Created { get; set; }
    public String Name { get; set; }
    public Boolean? Open { get; set; }
    public DateTime? Updated { get; set; }
    }

    When I should use something like:

    <Bag Id="" Open="">
    <Content></Content>

    Or

    <Bag Id="">
    <Content></Content>
    <Open></Open>
    </Bag>

    Please, see the difference between the Open and Id ...
    When should I use one or the other?

    Thanks,
    Miguel
    shapper, May 29, 2009
    #1
    1. Advertising

  2. If you websearch on this question -- when to use attributes vs. when to
    use children -- you'll find essentially the following advice:

    1) Attributes can't be repeated; child elements can. That is, you can have
    <Bag Id="" Open="">
    <Content></Content>
    <Content></Content>
    </Bag>
    but not two Open= attributes.

    2) Attributes can only have simple text as their values. If you may
    eventually want to structure the value, use a child element.

    3) Attribute values are normalized (that is, line-break characters get
    turned into spaces before the XML application sees them). I believe
    there are workarounds involving numeric character references, but in
    general, if you will want to retain newlines in the value you should use
    a child element.

    4) Attribute order is not meaningful, and the parser may return
    attributes to the application in any order. If the ordering of values is
    important to your application, attributes may not be the right choice.


    In other words, in many ways, attributes are inherently more limited
    than child elements.


    But sometimes a value really is intended to modify/qualify/identify a
    particular instance of an element or are "side information" to help
    describe how that element and its content should be interpreted, and
    will never be anything more than a single simple value. (Your Id=
    attribute is a case of the former; schema type overrides are an example
    of the latter.) In that situation, it may be easier for the humans who
    are reading the document and/or writing the software to process it if
    you make that value an attribute.




    So in the end, this is really a matter of style. I'd suggest you look at
    how attributes are used in markup languages written by other people --
    other XML documents, HTML, and so on -- as illustrations of how this
    decision has been made in the past. Then draw up a proposal, run it by
    your intended user community, and see if they have strong (and
    justified) opinions.
    Joe Kesselman, May 29, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Excluded_Middle

    Pointers to structure and array of structure.

    Excluded_Middle, Oct 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    740
    Martin Ambuhl
    Oct 26, 2004
  2. Leo Nunez
    Replies:
    3
    Views:
    1,192
    Neil Kurzman
    Feb 9, 2005
  3. Replies:
    2
    Views:
    592
  4. Replies:
    9
    Views:
    25,244
    Lal Bahadur Singh
    Nov 11, 2011
  5. meisterbartsch
    Replies:
    2
    Views:
    766
    meisterbartsch
    Jun 12, 2007
Loading...

Share This Page