I have given the local name of an element or attribute and the schema for the document. What is the easiest way to determine the basic datatype of the element or attribute. By basic datatype I mean the xs:string, xs:date etc. (The built in data types for the xml schema.)
One of the problems I face is that it is rare for the elements type to be one of the basic built in types. 99% of the time it is a complex type that 50% of the time refers to another complex type that refers to another complex type and so on.
A simple Example for this schema: I want to find the basic type for Employee/Person/Name/LastName (determine that LastName is xs:normalizedString).
In the schema Employee is defined as an xs:element and type=”bns:EmployeeType”
EmplyeeType has a Person element defined but it is type “PersonType” and then Name in person is NameType which is a complex type that extends GeneralName type that is type BasicNameType and that type finally defines the LastName which is of type “LastNameType” and on and on. There also definitions etc.
I am currently writing a parser using linq-to-xml to get at this but it isn’t easy or pretty. I have searched for other solutions and haven’t found any but I fully admit my XML/schema/XPath ignorance.
Is there an easy way to get the basic type for elements?
Don’t attempt to do this by hand.
I’m not familiar with Linq, so there might be other ways of doing this, but one way is to use schema-aware XSLT or XQuery. If you process your validated document using a schema-aware XSLT or XQuery processor then you will be able to do tests like
which is true if the context node is an attribute node that was validated against an attribute declaration whose governing type is xs:normalizedString.