最好的方式做XML,引号或其他方式 [英] The best way to do xml it, quotation marks or the other way

查看:106
本文介绍了最好的方式做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 称为元素personattribute .正如问题所述,另一种方法是


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 是元素personchild 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.


这篇关于最好的方式做XML,引号或其他方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆