2021年2月10日星期三

Can an XML element have both text and element content?

I have this XML element:

<address>123 main street Chicago IL 60605</address>  

Now let's say I want to add <country> element to it (and I insistent on country being an element not attribute), what would be right way to do that?

I can imagine it like this:

<address>  <country>USA</country>  123 main street Chicago IL 60605  </address>  

But the actual address above now looks somewhat tagless although I believe it's still a valid XML right?

I am asking because I haven't seen any example like above (in terms of learning XML format) where an element contains a child element but also an inline value as well.

And I know country being an attribute here would make a lot more sense but my question is about this way of format. If that's legal and acceptable or the actually address should be enclosed in another tag in later example like <street_address>?

https://stackoverflow.com/questions/66148477/can-an-xml-element-have-both-text-and-element-content February 11, 2021 at 11:44AM

没有评论:

发表评论