Download presentation
Presentation is loading. Please wait.
1
In this session, you will learn to:
Objectives In this session, you will learn to: Implement CDATA sections in an XML document Use the xml:lang attribute Validate an XML document Use Target namespaces
2
CDATA Sections in an XML Document
Inform the parser that the information contained in this section must be recognized as text and not as XML markup. A CDATA section should not include the string, ]]>, as its text because this string is used to indicate the end of a CDATA section. The following example depicts the usage of a CDATA section: <![CDATA[ The “]]>” string is used to indicate end of CDATA section]]> XML does not support nested CDATA sections. Are useful for writing XML code as text within an XML document.
3
The xml:lang Attribute
Used to specify the language of the text in a particular element. The following example depicts the usage of xml:lang attribute: <Message xml:lang="en">Hello</Message> <Message xml:lang="fr">Bonjour</Message> Value is applied to all the child elements of the element in which it is used, unless it is overridden with another instance of xml:lang.
4
Validating an XML Document
A valid XML document respects the syntax rules and also conforms to a structure as described in the schema. Parsers are used to validate the structure of an XML document. Parsers are of two types: Non-Validating Parsers: It builds a tree structure from tags used in an XML document and returns an error only when there is a problem with the syntax. Validating Parsers: It builds a tree, and compares the structure of an XML document with the structure specified in the associated XML schema.
5
Defines new elements and attributes.
Target Namespace Is a name space created by using the elements and attributes defined in namespace. Defines new elements and attributes. Are declared by using the targetNamespace attribute of the schema element. The following code snippet depicts the usage of targetNamespace attribute: <schema xmlns=” targetNamespace= purchase>
6
Best Practices Use UCC camel case for naming XML elements. The UCC camel case uses a small letter for the initial character of the XML element name and capitalizes the first character of every subsequent word. UCC camel case does not use spaces or hyphens between different words in the name of an XML element. An example is xmlTutorialBook. You can use UCC camel case in XML elements to ensure that the names adhere to XML standards and are more readable. Do not use XML namespaces in XML extensions, such as MathML and VoiceML. This is because each family of extensions should be distinguishable from XML core components and other extensions. This distinction ensures that there is no naming conflict among various XML extensions.
7
Tips and Tricks Always assign values to attributes. Unlike HTML, you should not leave an attribute in XML without a value assigned to it. Leaving an attribute without assigning a value to it violates the rules of XML. Avoid converting local type attributes to global type attributes unless it is imperative. This is because local type attributes impart a better abstraction to your design. However, you need to globalize the data type attributes that are needed by multiple elements. In addition, you need to globalize type attributes that act as base type attributes for other derived type attributes.
8
FAQs Who invented XML? Will XML replace HTML?
The XML development effort started in 1996 led by Jon Bosak of Sun Microsystems. Bosak organized a diverse group of markup language experts, from industry to academia, to develop a language that could be used to meet the challenges of large-scale electronic publishing. In February 1998, XML 1.0 specification became a recommendation by W3C. Today, the XML Core Working Group at W3C is responsible for developing and maintaining specifications for XML. Will XML replace HTML? XML is not designed to replace HTML. While the purpose of HTML is to present data, XML is designed to store data.
9
What are the applications for which XML can be used?
FAQs (Contd.) What are the applications for which XML can be used? XML is set to play an important role as a data interchange format in electronic business applications such as e-commerce and also in application integration. Another use of XML is for managing structured data, including information from databases. On the client side, XML can be used to create customized views to display data. Which browser can be used to view an XML document? Any browser that supports XML can be used to view an XML document. Some examples of browsers that support XML are Microsoft Internet Explorer 5.0, Netscape 6, Opera 7, and Mozilla Firfox Higher versions of the browsers mentioned here can also be used to view an XML document.
10
Why is XML called a case-sensitive language?
FAQs (Contd.) Why is XML called a case-sensitive language? XML is called a case-sensitive language because of the following reasons: Element names in XML are case sensitive. For example, the element, <Image> is different from the element, <image>. Therefore, if the opening tag of an element is written as <Image> and the closing tag is written as </image>, an error will be thrown. Attribute names in XML are also case sensitive. For example, <Image Width=“20in” Width=”10in”> will result in an error, while <Image Width=”20in” width=“10in”> will not. This is because, in the first example, the two attributes are exactly the same and will be considered as duplicates. In the second example, although the names of the attributes are the same, their capitalization is different. Therefore, they will be considered as two different attributes.
11
Challenge Bob is the EDP head of an organization that manufactures and sells hardware parts. The organization has presence in all the major cities of the United States. At present, all branch offices maintain their data locally. Bob wants to centralize the repository of the data in his organization. Data from all the branch offices needs to be collated and stored in a centralized location. Data pertaining to a branch should be available only to that branch office. However, the head office should be able to access all the data. In addition, Bob also wants that the sales personnel should be able to access sales data from mobile devices, such as palmtops and mobile phones. This sales information should have a brief description of the product, the price, and the available inventory.
12
Challenge (Contd.) Using which of the following markup languages can Bob achieve the preceding goals? HTML XML SGML VML Answer: SGML
13
Challenge (Contd.) Harry is creating an XML schema using XSD. He wants to use a data type that can store integers in the range 1 to 100 only. Which of the following data types should Harry use to accomplish this task? Derived Union List Answer: Derived
14
Challenge (Contd.) You have been assigned the task of developing an XML schema file for a new Web application in an organization. The application aims to deliver financial news to its subscribers. Financial news comprises of the date, the name of the organization, and the financial information. What should you use to represent the financial news in the XML schema? Complex type element Simple type element Element Attribute Answer: Complex type element
15
Challenge (Contd.) Joe wants to define an attribute, discount, in an XML schema. The XML document may or may not specify a value for this attribute. If the XML document does not specify a value for the attribute, the value of the discount attribute should be taken as 10%. Which of the following values of the use attribute should Joe specify for the discount attribute? optional default required fixed Answer: default
16
Challenge (Contd.) A user wants to declare a user-defined attribute, prodPrice, of the string type. The value for the prodPrice attribute must be provided in the XML document. Which of the following options correctly declares the prodPrice attribute? <xsd:attribute name="prodPrice" datatype="xsd:string" use="required“> <xsd:attribute name="prodPrice" type="xsd:string" use="required“> <xsd:attribute name="prodPrice" type="xsd:string" ref="required“> <xsd:attribute name="prodPrice" datatype="xsd:string" ref="required"> Answer: <xsd:attribute name="prodPrice" type="xsd:string" use="required">
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.