简体   繁体   中英

Are there problems with using the same name for an XML element and attribute?

Can I do something like this?

<root>
  <element>
     <child element="foo" />
  </element>
</root>

and like this?

<root>
  <element element="foo" />
</root>

Are there any drawbacks?

Technically, there is nothing preventing you to do that in XML. Nor at the XML Schema, XQuery or XSLT levels. Two aspects to take into account though:

  • what's the semantics of this? Is it really what you want, does it really make sense?
  • is it possible that one of the tools you will use will have some limitations in that regard? (none that I know of, but who knows, maybe one of those Java or C# "XML binding tools" that generate classes and fields based on the element and attribute names...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM