This question is plain ignorance, sorry. I can’t find the example I want. If I have a single element in an XML file and want to put a required attribute on it, what would be the XSD definition? The documentation I’ve seen seems to suggest that a type must be complex to include other elements or attributes. But when I try using complexType definition without other elements, I cannot add a “type” without anonymous child type complaints.
I am basically wanting something to define
Texty Texted Text
My searches keep showing me how to add attributes to complexTypes with multiple nested elements, which seems pretty straight forward. Can you help without laughing too much? I know this has to be simple. anAttribute is type xs:string as well as the type for anElement.
Thanks,
BBB
Simple types cannot have attributes, and string is a simple type. Therefore, you must define a complex type to carry the attribute declaration. To define a complex type that is based on the simple type string, you need to derive a new complex type from the simple type string:
Use the complexType element to start the definition of a new (anonymous) type. To indicate that the content model of the new type contains only character data and no elements, use a simpleContent element. Finally, derive the new type by extending the simple string type. The extension consists of adding a anAttribute attribute using a standard attribute declaration.