XML 요소에 대한 표준 명명 규칙이 있습니까? [닫은]
XML 문서에 대한 표준, 사실상 또는 다른 것이 있습니까? 예를 들어 태그를 작성하는 "가장 좋은"방법은 무엇입니까?
<MyTag />
<myTag />
<mytag />
<my-tag />
<my_tag />
마찬가지로 더 나은 속성에 대한 열거 값이 있다면
<myTag attribute="value one"/>
<myTag attribute="ValueOne"/>
<myTag attribute="value-one"/>
가장 일반적인 값은 camelCased-즉
<myTag someAttribute="someValue"/>
특히, 많은 언어가 공백이있는 열거 형을 허용하지 않기 때문에 (둘 사이의 매핑을 요구하는) 코드 생성기와 혼합하면 공백이 몇 가지 결함을 유발합니다 (즉, xml을 객체로 [비 직렬화]).
XML 명명 규칙
XML 요소는 다음 이름 지정 규칙을 따라야합니다.
- Element names are case-sensitive
- Element names must start with a letter or underscore
- Element names cannot start with the letters xml(or XML, or Xml, etc)
- Element names can contain letters, digits, hyphens, underscores, and periods
- Element names cannot contain spaces
모든 이름을 사용할 수 있으며 단어는 예약되지 않습니다 (xml 제외).
최상의 명명 방법
- Create descriptive names, like this: <person>, <firstname>, <lastname>.
- Create short and simple names, like this: <book_title> not like this: <the_title_of_the_book>.
- Avoid "-". If you name something "first-name", some software may think you want to subtract "name" from "first".
- Avoid ".". If you name something "first.name", some software may think that "name" is a property of the object "first".
- Avoid ":". Colons are reserved for namespaces (more later).
- Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software doesn't support them.
이름 지정 스타일
XML 요소에 대해 정의 된 이름 지정 스타일이 없습니다. 그러나 다음은 일반적으로 사용되는 몇 가지입니다.
- Lower case <firstname> All letters lower case
- Upper case <FIRSTNAME> All letters upper case
- Underscore <first_name> Underscore separates words
- Pascal case <FirstName> Uppercase first letter in each word
- Camel case <firstName> Uppercase first letter in each word except the first
참조 http://www.w3schools.com/xml/xml_elements.asp
저에게 이것은 프로그래밍 언어의 코드 스타일에 대해 논의하는 것과 같습니다. 일부는 스타일을 주장하고 다른 일부는 대안을 옹호합니다. 내가 본 유일한 합의는 "하나의 스타일을 선택하고 일관성을 유지하라"는 것입니다!
많은 XML 방언이 소문자 이름 (SVG, Ant, XHTML ...)을 사용한다는 점에 주목합니다.
"속성 값에 공백 없음"규칙이 없습니다. 어떻게 든, 그것은 "속성에 무엇을 넣고 무엇을 텍스트로 넣을 것인가?"라는 토론에 보냅니다.
이것이 최선의 예는 아니지만 속성에 공백을 사용하는 잘 알려진 XML 형식이 있습니다.
- XHTML, 특히 클래스 속성 (두 개 이상의 클래스를 넣을 수 있음)과 물론 alt 및 title 속성.
- 예를 들어 경로 태그의 d 속성이있는 SVG.
- 둘 다 스타일 속성 ...
I don't fully understand the arguments against the practice (seem to apply to some usages only) but it is legal at least, and quite widely used. With drawbacks, apparently.
Oh, and you don't need a space before the auto-closing slash. :-)
I favour TitleCase for element names, and camelCase for attributes. No spaces for either.
<AnElement anAttribute="Some Value"/>
As an aside, I did a quick search for Best Practices in XML, and came up with this rather interesting link: XML schemas: Best Practices.
I would tend to favour lowercase or camelcase tags and since attributes should typically reflect data values - not content - I would stick to a value which could be used as a variable name in whatever platform/language might be interested, i.e. avoid spaces but the other two forms could be ok
It's subjective, but if there are two words in an element tag, the readibility can be enhanced by adding an underscore between words (e.g. <my_tag>
) instead of using no separator. Reference: http://www.w3schools.com/xml/xml_elements.asp. So according to w3schools the answer would be:
<my_tag attribute="some value">
The value needn't use an underscore or separator, since you are allowed spaces in attribute values but not in element tag names.
Many document centred XML dialects use lower case basic Latin and dash. I tend to go with that.
Code generators which maps XML directly to programming language identifiers are brittle, and (with the exception of naive object serialisation, such as XAML) should be avoided in portable document formats; for best reuse and information longevity the XML should try to match the domain, not the implementation.
rss is probably one of the most consumed xml schemas in the world and it is camelCased.
Spec is here: http://cyber.law.harvard.edu/rss/rss.html
Granted it has no node attributes in the schema, but all the node element names are camelCased. For example:
lastBuildDate managingEditor pubDate
I normally align XML naming convention with the same naming convention in other parts of code. The reason is when I load the XML into Object its attributes and element names can be referred as the same naming convention currently used in the project.
For example, if your javascript using camelCase then your XML uses camelCase as well.
Microsoft embraces two convention:
For configuration, Microsoft uses camelCase. Look at Visual Studio config file. For VS2013, it is stored in:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe.config
Example:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
- Microsoft also uses UpperCase for their XAML. I guess it is to differentiate from HTML (which uses lowercase).
Example:
<MenuItem Header="Open..." Command="ApplicationCommands.Open">
<MenuItem.Icon>
<Image Source="/Images/folder-horizontal-open.png" />
</MenuItem.Icon>
</MenuItem>
There is no explicit recommendation. Based on other recommendation from W3C, the one for XHTML, I've opted for lowercase:
4.2. Element and attribute names must be in lower case
XHTML documents must use lower case for all HTML element and attribute names. This difference is necessary because XML is case-sensitive e.g. <li> and <LI> are different tags.
XML Naming Rules
XML elements must follow these naming rules:
- Names can contain letters, numbers, and other characters
- Names cannot start with a number or punctuation character
- Names cannot start with the letters xml (or XML, or Xml, etc)
- Names cannot contain spaces Any name can be used, no words are reserved.
Source: W3 School
I have been searching a lot for a good approach, also reading this thread and some others and I would vote for using hyphens.
They are used broadly in ARIA ( https://developer.mozilla.org/de/docs/Web/Barrierefreiheit/ARIA ) which can be seen in many source codes and are therefore common. As already pointed out here, they are certainly allowed, which is also explained here: Using - in XML element name
Also as a side benefit: When writing HTML in combination with CSS, you often have classes whose names use hyphens as separator by default as well. Now, if you have custom tags that use CSS classes or custom attributes for tags that use CSS classes, then something like:
<custom-tag class="some-css-class">
is more consistent and reads - in my humble opinion - much nicer than:
<customTag class="some-css-class">
참고URL : https://stackoverflow.com/questions/442529/is-there-a-standard-naming-convention-for-xml-elements
'programing tip' 카테고리의 다른 글
SVN 개정 번호를 내 ASP.NET 웹 사이트와 어떻게 동기화합니까? (0) | 2020.09.06 |
---|---|
0x 표기법을 사용하는 숫자는 무엇을 의미합니까? (0) | 2020.09.06 |
IList 또는 IEnumerable을 배열로 변환하는 가장 좋은 방법 (0) | 2020.09.05 |
중첩 된 HTML 주석이 가능합니까? (0) | 2020.09.05 |
CMake를 사용하여 CTest에서 자세한 출력을 얻으려면 어떻게해야합니까? (0) | 2020.09.05 |