开发者

How to give the "Root Element" name in two Words In XML [duplicate]

This question already has answers here: 开发者_JAVA百科Encoding space character in XML name (2 answers) Closed 5 years ago.

I want to give the root element name as two words, how to give it..

for Example,

<parent>
  <child1>content</child1>
  <child2>content</child2>
</parent>

Root Element "Parent" has to be given as "Parent Name" I Want to use SPACE in the Root Element


XML Elements cannot have spaces in their names. That's the rule.

If you are converting to/from a data source with spaces in the field names, then you'll need to change those spaces into something else during the conversion process.

I suggest using underscores, as this is a valid character in XML element names - eg <parent_name>

You can also use hyphens if you prefer. Dots, colons and some other punctuation characters are also okay, but can get complicated (eg because colons are also used for name-spacing), so best to avoid them and stick with hyphens and underscores.

The other common way of representing multiple words in an element name is to use camel case, which is where your element name has capital letters to represent the start of each word - eg <ParentName>.

You might want to read this question here on SO for more discussion on this: Is there a standard naming convention for XML elements?

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜