Results 1 to 7 of 7

Thread: XML best practice - elemenst or attributes

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    XML best practice - elemenst or attributes

    Howdy

    When persisting recors to XML what is the best practice regarding whether a field should be persisted as an Attribute or an Element? I've kind of settled on having my key fields as attributes but is that good practice, bad practice or neither?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XML best practice - elemenst or attributes

    I've done it both ways... often, it's like anything else - it depends on what works. There's "purists" in both camps. I'm on the fence. I tend to want to put things in to attributes if it's something like a property of that element. Unless it's longer text or text that may have special characters, in which case I'll use elements.

    Having Key items as attributes makes sense, it's data that uniquely identifies the item. I don't know if it's best practice or bad, but I'd say it's probably common practice.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: XML best practice - elemenst or attributes

    My rule is that it is an element unless it is an attribute of that element like so


    Code:
    <Person>
        <Details AreUpToDate="yes">
              <PhoneNumber IsActive="No">0871234567</PhoneNumber>
        </Details>
    </Person>

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: XML best practice - elemenst or attributes

    Quote Originally Posted by DeanMc View Post
    My rule is that it is an element unless it is an attribute of that element like so
    I take it the attributes are bits in red? Can the attributes value be changed pragmatically without manually editing it?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: XML best practice - elemenst or attributes

    Quote Originally Posted by DeanMc View Post
    My rule is that it is an element unless it is an attribute of that element like so


    Code:
    <Person>
        <Details AreUpToDate="yes">
              <PhoneNumber IsActive="No">0871234567</PhoneNumber>
        </Details>
    </Person>

    OK - but if you turn that into a class are both PhoneNumber and IsActive properties? or is IsActive a method?

  6. #6
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: XML best practice - elemenst or attributes

    @Nightwalker, of course... In LINQ its very easy to do.

    @Merrion, well they would all be properties if they need to be referenced outside the class. The key is which data container to use. Since Phone number contains more than one piece of data it becomes complex and therefore needs to either be a class or structure depending on how complex it it and how you wish to use it.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: XML best practice - elemenst or attributes


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width