Cheap Web Hosting for Developers

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION The xsd:union element takes

Filed under: PHP and XML — webmaster @ 02:15

CHAPTER 3 VALIDATION The xsd:union element takes the attribute memberTypes, which is a whitespace-delimited list of data types to combine. In this case, you are using the AtoZ and oneToTen types. An element declared with this type for instance, myunionvals could look like the following: A 1 I 9 Complex Types and Content Within the earlier discussion of XML Schemas, you saw how to use a complex type when declaring elements. You have yet to look at complex content as well as the built-in complex data type within the XML Schema specification. This is the anyType data type. Any/Empty As mentioned earlier, ANY and EMPTY either allow anything as element content (ANY) or allow nothing for element content (EMPTY). The equivalent data type using XML Schemas for ANY is the anyTypedata type: By this declaration, the element description is completely unrestrained. It can consist of any type of content and any type of child elements. The elements any and anyAttributealso exist, which you can use to provide similar functionality in a more limited scope: This syntax should look familiar to you. It is a declaration for the myelement element containing child elements, as noted by the xsd:sequence element. The new element within the sequence, xsd:any, indicates that after a definedelement element any element may appear. The element need not even be declared within the schema. The minOccurs attribute indicates there could be zero or one element. The maximum value is from the default value for maxOccurs, which was not explicitly set. The xsd:anyAttribute element allows any number of attributes for the element without restricting which ones are allowable. The attribute processContents does allow for some level of control over attribute availability. The value skip, as used in the declaration, allows for any attribute, even ones that have not been defined in the schema. A value of strict, which is also the default value if processContents is omitted, will allow only those attributes that have been declared in the schema. The third possible value is lax. This value means that if an attribute is

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION This definition would allow

Filed under: PHP and XML — webmaster @ 16:35

CHAPTER 3 VALIDATION This definition would allow numbers such as 1.11, 1.0, 1.1, and 1. The total number of digits never exceeds three, and the number of decimal places never exceeds two. More Simple Types So far, you have seen how to use some built-in simple types as well as create user-derived types. XML Schemas offer two additional varieties of simple types. They are the list and union data types. List Type A list type is similar to NMTOKENSas used in a DTD for an attribute declaration. The value contains tokens separated by whitespace. In fact, NMTOKENSis a built-in derived data type for schemas. List types are more restrictive than NMTOKENS, though. The tokens are restricted to certain values that you define. Using the CreditTypedefinition created in Listing 3-27, you can create a data type that will accept multiple values that conform to the CreditTypedefinition and be separated by whitespace: The xsd:list element takes the attribute itemType, which names the data type that defined the acceptable values. Based on this definition and an element named creditlist, which is declared with this type, it could take the following form: 1.0 1.5 2.0 Union Type Union types enable values to be provided from multiple data types rather than just a single data type. If you were to define a type that was restricted to a single alpha character (A though Z) such as this: then you could join this via a union with the oneToTen type defined in Listing 3-28:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION minInclusive /maxInclusive/minExclusive/maxExclusive These facets

Filed under: PHP and XML — webmaster @ 04:21

CHAPTER 3 VALIDATION minInclusive /maxInclusive/minExclusive/maxExclusive These facets set either inclusive or exclusive bounds for values. inclusive means the value must belong within the range, and exclusive means the value must belong outside the range. Though not required to do so, normally the minInclusive and maxInclusivefacets are used together to define a range. You could define a range from 1 to 10, as in Listing 3-28. Listing 3-28. Defining Ranges You could also represent this with the following: You could also define a type for integers greater than ten: totalDigits/fractionDigits These allow you to set the number of digits allowed. The totalDigits facet indicates the maximum total number of digits, and fractionDigits indicates the maximum number of decimal places. When used together, fractionDigits can never have a value greater than the number of totalDigits. Also, if defining a type with a base type that includes these, the values may not be greater than defined in the base type. For example:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION length/minLength/maxLength All three of

Filed under: PHP and XML — webmaster @ 17:30

CHAPTER 3 VALIDATION length/minLength/maxLength All three of these can limit the length of a data type. Using length restricts data to be exactly the number of units set, and minLength and maxLength restrict data to be at least minLength and/or no more than maxLength. The term units is used as the base data type and determines what constitutes a unit. For instance, a string type consists of characters, so a unit is a character. List types, which you haven t come to yet, consist of items, so a unit in that case is an item. Suppose data for the titleelement of a course is coming from a database. The field is set to VARCHAR(255), and the application handling the data enforces that it must have at least five characters. You can create a type that would also enforce this within the XML document: The new declaration for the title element would be as follows: If, for some reason, the data were corrupted and a title came in as , it would be caught when validated against the schema. pattern pattern restricts a value to one matching a regular expression. A simple case for this would be validating an email address: The xsd:pattern element is wrapping within the example. You have to deal with some whitespace issues when physically inserting a line feed and then trying to match against a value. whiteSpace A whiteSpaceelement is used in a similar manner as xml:spacefrom Chapter 2, though it provides functionality. Using the whiteSpacefacet, the values can be preserve, replace, or collapse. Values preserving whitespace leaves it intact. Values replacing whitespace will convert #x9(tab), #xA(line feed), and #xD(carriage return) into #x20(spaces). Values collapsing whitespace will first process the value using replace and then convert all contiguous sequences of #x20(spaces) into a single #x20. Leading and trailing spaces are also removed from the value. The following example is defined within the context of an element declaration to illustrate that these definitions need not be named:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION User-Derived Types So far,

Filed under: PHP and XML — webmaster @ 05:47

CHAPTER 3 VALIDATION User-Derived Types So far, you have seen how to use some built-in simple types. XML Schemas are extensible, which allows you to define your own data types by deriving a type from a simple type. Take, for example, the declaration for the credits element in Listing 3-26. It is a decimal data type, so the values it can take are pretty much endless. Say you want to limit the possible values to 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, and 4. You can t use a built-in type directly, so you must create your own that will be derived from the decimal data type, as shown in Listing 3-27. Listing 3-27. Enumeration Facet for CreditType The xsd:simpleType element has been given a name, CreditType, this time. Rather than being contained within an element declaration, this definition can live as a child of the schema element and be referenced directly by the typeattribute of the element that wants to use this data type. The xsd:restriction element is how user-derived types are defined. These types are created through restrictions on existing types. In this case, the existing type is xsd:decimal, as indicated by the base attribute. The restriction being placed on it is an enumeration of acceptable values, as indicated by the use of the xsd:enumeration elements. The value of the value attribute sets an acceptable value for the content when used in an XML document. Based on this definition, you can modify the credits element to use this new data type: The value for the type attribute is CreditType, which is the name of the derived type you created. It is not prefixed by xsdbecause this type is not part of the XML Schema specification. Rather, this definition is a user-derived type, so the schema knows to not look within its built-in types. You could use this type with an attribute declaration, such as . enumeration is just one of the constraining facets that is available. Constraining facet just means it can be used to restrict values for a data type. The availability of constraining facets is determined by the data type being derived. Not all facets are applicable to every data type. You can use 11 other facets.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION The xsd:group element is

Filed under: PHP and XML — webmaster @ 18:41

CHAPTER 3 VALIDATION The xsd:group element is laid out similarly to the xsd:element elements. Notice within the xsd:sequence elements for the element declarations that the xsd:group element does not include a name attribute, but rather a ref attribute. This attribute instructs the XML Schema to reference the group named Address. The ShippingAddressdeclaration also shows how you can use a group as well as declare additional elements. Attributes I ve shown only simple attribute declarations up until this point. You can set additional pieces of information when declaring attributes, such as attribute defaults used in a DTD. You can also group and reference attributes when declaring an element. Groupings make it simple to define a set of attributes common to many different elements. Attribute Declaration An attribute declaration has three attributes that handle setting these values. The default attribute takes a string value to set a default value for an attribute if the attribute is not set on an element. The fixed attribute sets a fixed string value for an attribute. The last attribute, use, determines how to use the attribute. The possible values for the use attribute are optional, which is also the default; required; and prohibited. The prohibited value is one you probably don t know. It does not have a corresponding counterpart in a DTD. This value means that the attribute cannot be used. For example: You must never use the attributes fixedand default at the same time. These conflict with each other and will cause an error in the schema. Attribute Groups You can group attributes just as you can group elements. You may run into cases where you have a set of attributes applicable to a few difference elements. You may also want to group attributes just to make the schema easier to read. You group attributes by using the attributeGroup element: You can use the attributeGroupelement in the same way as you used a groupelement for elements. The attribute refreferences the xsd:attributeGroupelement named movieattributes.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION same thing. For instance,

Filed under: PHP and XML — webmaster @ 08:25

CHAPTER 3 VALIDATION same thing. For instance, the element rueis the same as the element street. Based on these declarations, the following two documents are both valid:

Element Groups The sequence element you have seen used earlier in the chapter, such as within Listing 3-26, is a form of grouping. It is an unnamed local group. Groups may also be choice or all. A sequence, as you already know, means the elements must appear in that exact sequence. A choicemeans that a certain number determined by the maxOccurs and minOccurs attributes, which both default to 1, may be selected. Using all allows the elements to appear in any order, although all the elements must be present within the content of a parent element. When you create named groups, you can share them so you don t need to define local groups. You can just reference the named group. Take the case of an address. A document may have a shipping address as well as a billing address. In most cases, the elements required are the same. You could create a named group and share between the two, as follows:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP MySQL Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION When the element myelement

Filed under: PHP and XML — webmaster @ 22:27

CHAPTER 3 VALIDATION When the element myelement is used in a document and is empty, the content is automatically set to some text. The element secondelementbehaves the same way, but if it already contains content, the content must match the string set by the fixed attribute; otherwise, it is not valid. Elements may use either default or fixed, but not both. NULL Value Comparing XML data to data from a database, you can t easily distinguish between an empty string and a NULL value. You could devise your own XML structure to add support for this, or you could do it through an XML Schema. Element declarations include the attribute nillable. It is a Boolean, with a default value of false, used to indicate whether an empty element is NULL. For example: Using this attribute also requires the use of the http://www.w3.org/2001/ XMLSchema-instance namespace in the XML document. Assuming the prefix xsi was set for this namespace within the XML document, the element mydata could appear as follows: Element Substitution Schemas allow for element name substitutions. Take the case where a company has an office in the United States and one in France. The office in the United States creates most of their XML documents in English, and the office in France uses French for theirs. A shared schema could allow element names from either language: Notice the elements with the substitutionGroup attribute. These element declarations are not defining anything other than a name and a substitionGroup, which refers to another element declaration. This allows element names to be used interchangeably and mean the

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION You probably now understand

Filed under: PHP and XML — webmaster @ 11:20

CHAPTER 3 VALIDATION You probably now understand why you took the inside-out approach rather than a top- down approach for this introduction to XML Schemas. Up to this point, I have not covered all the basic syntax and functionality, but you should now have a good working knowledge to start taking a more in-depth look at them. Understanding the Structure So far I ve only touched on XML Schema structures a bit. An interesting aspect of schemas is that virtually all XML Schema elements (meaning the elements in general such as xsd:attribute, xsd:element, and xsd:complexType) will accept any attributes outside the XML Schema namespace. For example, if you have a namespace declared as xmlns:foo=”http:// www.example.com/foo” within the schema, you can add arbitrary attributes to schema elements. (I ll cover namespaces in detail later in the Namespaces section.) For example: It is perfectly valid to add a foo:myattattribute. Though not affecting validation, you may want some additional information within your schema for some other reason. You cannot, however, add attributes from the xsdnamespace that do not belong on an element. For example: Elements You can perform other tasks with elements than just those shown earlier in the chapter. Elements may have default content or NULL values. This may be substituted and may be grouped. Default Content Recall the attribute-list declaration in a DTD. Attributes can specify default as well as fixed values. Using XML Schemas, you can do the same to elements. The defaulted or fixed content is a string, so the data type for an element must support this type of content. For example:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services

PHP, MySQL, Java, Unix Cheap Web Hosting

CHAPTER 3 VALIDATION Just like the pre-requisite

Filed under: PHP and XML — webmaster @ 00:33

CHAPTER 3 VALIDATION Just like the pre-requisite declaration in Listing 3-25, the course declaration is following the same rules, including the number of times this element may appear as a child element within the courseelement. Again, this is a complex type, noted by the xsd:complexTypeelement, and is defined within the scope of the declaration. This time, however, multiple elements reside within the xsd:sequenceelement. The elements, when appearing within the XML document, must follow the order title, description, credits, lastmodified, and pre-requisite. Note that the declaration for pre-requisitein Listing 3-25 was left out for brevity. When you finish constructing the schema, it will be laid out for you in its entirety. For now the missing declaration is noted by an XML comment. If you recall the rules regarding minOccursand maxOccurs, they default to 1when not present on an element. By omission, each of the element declarations within the xsd:sequenceelement must appear exactly one time in the order specified. The only exception is the pre-requisite element. Although it still must obey the element ordering, it is not required to appear as a child element because those attributes were explicitly set on its declaration. The final piece is to build the declaration for the courses element, which is the root of the XML document. If you have been following along, you should have no problem with the last piece of the puzzle. Listing 3-26 shows the entire schema, including the courseselement declaration, which would constitute the contents of the courses.xsd file. With this schema, the course document from Listing 3-24 is perfectly valid. Listing 3-26. XML Schema for the Courses Document

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services

« Previous PageNext Page »

Powered by Cheap Web Hosting