最好的方式做XML,引号或其他方式
嗨!
我正在尝试制作XML文件,但是现在问题来了.我现在可以看到有些正在使用元素,例如:< name> John</name>并且有人喜欢在引号< name ="John">之间使用这种方式.
这两种编码方式之间的区别是什么?
一种方法比另一种更好吗?
[edit]删除了不必要的代码标签-nelek [/edit]
Hi!
I’m trying to make a XML file, but the now the problem comes. I can now see that some are using Elements like: <name>John</name> and someone likes to do it this way between quotation marks <name ="John">.
What is the different between this and that way of doing these two coding and what are they called?
Is one way better than the other?
[edit] Unnecessary code tags removed - nelek [/edit]
在XML<name =John>
中在语法上不正确.应该是这样的
In XML<name ="John">
is not syntactically correct. It should be something like this
<person name="John"></person>
然后person
称为element
,而name
称为元素person
的attribute
.正如问题所述,另一种方法是
Then person
is called element
and name
is called the attribute
of the element person
. As said in the question the other way of doing this is
<person>
<name>John</name>
</person>
在这里,name
是元素person
的child element
.
两者都给出信息.关于何时使用attribute
和何时使用child element
没有严格的规则.但是,一般而言,当与有关元素有关的信息describes something
像形容词有关名词时,都可以使用该属性.另一方面,当相关信息如data
时可以使用元素.
另一个区别是,如果将其表示为元素,则可以nest
其他元素,也可以具有attributes
.但是,如果将其作为属性给出,则它不能具有子元素和其他属性.
这里给出了解释
http://www.w3schools.com/dtd/dtd_el_vs_attr.asp [ http://msdn.microsoft.com/en-us/library/7f0tkwcx (v = vs.80).aspx [
Here, name
is the child element
of the element person
.
Both, give the information. There are no hard and fast rules regarding when to use as an attribute
and when to use as child element
. But, as a general the attribute can be used when the information concerned describes something
about the element concerned, like an adjective describes about a noun. On the other hand an element can be used when the information concerned is like data
.
The other difference is that if it is represented as an element then it can nest
other elements and also can have attributes
. But, if it is given as an attribute then it cannot have child elements and other attributes.
An explanation is given here
http://www.w3schools.com/dtd/dtd_el_vs_attr.asp[^]
http://msdn.microsoft.com/en-us/library/7f0tkwcx(v=vs.80).aspx[^]
I think it may be helpful.