View Full Version : [XSD] Question on xsd:element -> name (Optional?!)
Aradon
11-15-2007, 05:25 PM
So I was reading through the docs of some xsd stuff and I noticed this little quip about element for name:
name
The name of the element. The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification. Name and ref attributes cannot both be present.
Required if the containing element is the schema element.
Optional.
So wait, does this mean that name is optional? If so what happens if you DON'T use name? Does that mean someone can create an xml element of any name ?
shyam
11-15-2007, 07:31 PM
name
The name of the element. The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification. Name and ref attributes cannot both be present.
this actually means any element like xsd:simpleType, xsd:complexType, xsd:sequence etc.
Required if the containing element is the schema element.
Optional.
this specifically means the xsd:element
So wait, does this mean that name is optional? If so what happens if you DON'T use name? Does that mean someone can create an xml element of any name ?
actually this is also possible but, u have to give the name of the parent element whose content can be any arbitrarily valid xml. its defined as
<xsd:element name="anything" type="xsd:anyType"/>
Aradon
11-19-2007, 03:34 PM
Now here's a question. I realize that you can create this any type, but can you create an any element that has specific elements underneath it?
So we could have something like
<startXML>
<any1>
<required1 randomattribute= "yar"/>
</any1>
<any2>
<required1 randomattribute="Nos"/>
</any2>
</startXML>
rpgfan3233
11-19-2007, 04:07 PM
Now here's a question. I realize that you can create this any type, but can you create an any element that has specific elements underneath it?
So we could have something like
<startXML>
<any1>
<required1 randomattribute= "yar"/>
</any1>
<any2>
<required1 randomattribute="Nos"/>
</any2>
</startXML>
I'm an XML Schema newbie, so forgive me if I am misleading. I think that would be the point of xs:group, unless you are talking about a generic any type instead of a custom type. In the generic case, I'm thinking the answer is no, mainly because xs:any allows for something like <xhtml:p> from XHTML or <math:mrow> from MathML, for example. There is no way you can control things like that.
shyam
11-20-2007, 03:11 PM
Now here's a question. I realize that you can create this any type, but can you create an any element that has specific elements underneath it?
if i understand ur question right...you have an element that is of anyType and within the content of this u want to check for the presence of a particular required attribute/element...
in that case no. you cannot have schema rules for content within an element that can contain anything
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.