|
-
Jul 9th, 2009, 10:40 AM
#1
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?
-
Jul 9th, 2009, 11:39 AM
#2
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
-
Jul 11th, 2009, 06:47 AM
#3
Frenzied Member
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>
-
Jul 13th, 2009, 01:29 AM
#4
Re: XML best practice - elemenst or attributes
 Originally Posted by DeanMc
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
-
Jul 13th, 2009, 03:41 AM
#5
Re: XML best practice - elemenst or attributes
 Originally Posted by DeanMc
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?
-
Jul 13th, 2009, 07:01 AM
#6
Frenzied Member
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.
-
Jul 15th, 2009, 05:03 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|