473,414 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Can Element be same as Attribute name?

Hi,

I am new to XML. Is following XML write? Or it can cause errors for
other developers using/parsing my XML output in their respective
applications.

<emp id="101" name="ABC">
<name>ABC</name>
<age>23</age>
<gender>Male</gender>
<joindate>
<day>21</day>
<month>5</month>
<year>2000</year>
</joindate>
</emp>

The attribute name & element name can have different values!

Regards

Aug 18 '05 #1
3 1265
I would question having the attribute named "name" of element "emp" in
this specific example?

I would have written..

<emp id="101">
<name>ABC</name>
<age>23</age>
<gender>Male</gender>
<joindate>
<day>21</day>
<month>5</month>
<year>2000</year>
</joindate>
</emp>

Regards,
Mukul

Aug 18 '05 #2


go***@rediffmail.com wrote:

Is following XML write? Or it can cause errors for
other developers using/parsing my XML output in their respective
applications.

<emp id="101" name="ABC">
<name>ABC</name> The attribute name & element name can have different values!


An XML parser checking for well-formedness will certainly not give any
errors just because there is an attribute and a child element of the
same name. So parsing that XML works fine.
Whether it is good and clear design is another question.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 18 '05 #3
go***@rediffmail.com wrote:
Hi,

I am new to XML. Is following XML write? Or it can cause errors for
other developers using/parsing my XML output in their respective
applications.

<emp id="101" name="ABC">
<name>ABC</name>
<age>23</age>
<gender>Male</gender>
<joindate>
<day>21</day>
<month>5</month>
<year>2000</year>
</joindate>
</emp>

The attribute name & element name can have different values!


Yes, this is correct...elements and attributes are separate territories.

But the argument about whether to use elements or attributes is a large
one, and has no perfect solution. See the FAQ page about this at
http://xml.silmaril.ie/developers/attributes/

Personally, I prefer to keep attributes for numerical and categorical
data, and keep element content for arbitrary text like names, so I'd
recommend something like this:

<employee id="X101" gender="male" joined="2000-05-21" dob="1982-10-24">
<name>
<given>Thomas</given>
<called>Peter</called>
<family>Flynn</family>
</name>
...other elements in here...
</employee>

a) If you're going to use an identity value which is (by definition) unique,
make it an XML ID so that any errors will get picked up by the validator
before anything worse happens. This carries the unfortunate restriction
that values must begin with a letter, but this is a small price to pay
for a big benefit.

b) Categories are best handled by token list attributes which are controlled
vocabularies, so again the validating parser can spot any errors at an
early stage. Gender is usually just one of two choices :-)

c) There is no need to specify ages if you store dates. It's much easier and
more accurate to process dates, and they don't usually ever change data
(assuming they were input correctly). If you store dates, always use the
ISO 8601 format, as this is completely unambiguous and has the advantage
of being in sortable form. I've taken to naming date attributes with the
symbolic format just to make them obvious to the human eye, eg
joined.YYYY-MM-DD="2000-05-21"

But this is just my personal preference: what suits my data may not suit
yours.

///Peter
--
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"
Aug 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Howden | last post by:
I'm trying to define a schema element (allPeriodData) containing up to 50 different decimal child elements (periodData). Each child element (periodData) identifies itself with an ID having a value...
0
by: Ingrid | last post by:
Am I right in thinking that datatyping at element level ie <xs:element name="num" type="xs:integer"> and specifying a choice of attribute values ie <xs:attribute name="kind"> <xs:simpleType>...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
0
by: magister | last post by:
Hello, I want to have a unique Quesiton Id key for each question under section. Not for every question in the Typed DataSet. Is there anyway I can do this...? Thanks, here is my typed...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
2
by: Json | last post by:
Ok, brand new to SQLXML 3.0 and its various issues. Heres what I'm trying to do: 1. I am trying to load xml data into an empty SQL table from my .NET console application. 2. This isn't a huge...
14
by: kelvin.jones | last post by:
Hi, if I had the ID of an input element, how can I find the input's FORM in javascript? Basically, given a input's dom id, I want to insert something in the onSubmit of the Form that that input...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
4
by: Eric | last post by:
Attached is an example of my question. Note the "values" attribute is optional. Also the <valuesub-element is optional. Here, the XML can contain, 1 or both or neither. I would like to allow...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.