Attributes Elements can have attributes <coursecourse id="CS-101"> <title>Intro.to Computer Science</title> <dept name>Comp.Sci.</dept name> <credits>4 </credits> </course> Attributes are specified by name=value pairs inside the starting tag of an element An element may have several attributes,but each attribute name can only occur once <course course id=“CS-101”credits=“4"> Database System Concepts-6th Edition 23.12 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 23.12 ©Silberschatz, Korth and Sudarshan th Edition Attributes Elements can have attributes <course course_id= “CS-101”> <title> Intro. to Computer Science</title> <dept name> Comp. Sci. </dept name> <credits> 4 </credits> </course> Attributes are specified by name=value pairs inside the starting tag of an element An element may have several attributes, but each attribute name can only occur once <course course_id = “CS-101” credits=“4”>
Attributes vs.Subelements Distinction between subelement and attribute In the context of documents,attributes are part of markup,while subelement contents are part of the basic document contents In the context of data representation,the difference is unclear and may be confusing Same information can be represented in two ways -<course course id=“CS-101”>..</course> <course> <course_id>CS-101</course id>... </course> Suggestion:use attributes for identifiers of elements,and use subelements for contents Database System Concepts-6th Edition 23.13 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 23.13 ©Silberschatz, Korth and Sudarshan th Edition Attributes vs. Subelements Distinction between subelement and attribute In the context of documents, attributes are part of markup, while subelement contents are part of the basic document contents In the context of data representation, the difference is unclear and may be confusing Same information can be represented in two ways – <course course_id= “CS-101”> … </course> – <course> <course_id>CS-101</course_id> … </course> Suggestion: use attributes for identifiers of elements, and use subelements for contents
Namespaces XML data has to be exchanged between organizations Same tag name may have different meaning in different organizations, causing confusion on exchanged documents Specifying a unique string as an element name avoids confusion Better solution:use unique-name:element-name Avoid using long unique names all over document by using XML Namespaces <university xmIns:yale="http://www.yale.edu"> <yale:course> <yale:course id>CS-101 </yale:course id> <yale:title>Intro.to Computer Science</yale:title> <yale:dept_name>Comp.Sci.</yale:dept_name> <yale:credits>4 </yale:credits> </yale:course> </university> Database System Concepts-6th Edition 23.14 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 23.14 ©Silberschatz, Korth and Sudarshan th Edition Namespaces XML data has to be exchanged between organizations Same tag name may have different meaning in different organizations, causing confusion on exchanged documents Specifying a unique string as an element name avoids confusion Better solution: use unique-name:element-name Avoid using long unique names all over document by using XML Namespaces <university xmlns:yale=“http://www.yale.edu”> … <yale:course> <yale:course_id> CS-101 </yale:course_id> <yale:title> Intro. to Computer Science</yale:title> <yale:dept_name> Comp. Sci. </yale:dept_name> <yale:credits> 4 </yale:credits> </yale:course> … </university>
More on XML Syntax Elements without subelements or text content can be abbreviated by ending the start tag with a /and deleting the end tag <course course id=“CS-101”Title=“Intro.To Computer Science” dept_name=“Comp.Sci."credits=“4”/> To store string data that may contain tags,without the tags being interpreted as subelements,use CDATA as below <![CDATA[<course>...</course>]]> Here,<course>and </course>are treated as just strings CDATA stands for“character data” Database System Concepts-6th Edition 23.15 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 23.15 ©Silberschatz, Korth and Sudarshan th Edition More on XML Syntax Elements without subelements or text content can be abbreviated by ending the start tag with a /> and deleting the end tag <course course_id=“CS-101” Title=“Intro. To Computer Science” dept_name = “Comp. Sci.” credits=“4” /> To store string data that may contain tags, without the tags being interpreted as subelements, use CDATA as below <![CDATA[<course> … </course>]]> Here, <course> and </course> are treated as just strings CDATA stands for “character data
XML Document Schema Database schemas constrain what information can be stored,and the data types of stored values XML documents are not required to have an associated schema However,schemas are very important for XML data exchange Otherwise,a site cannot automatically interpret data received from another site Two mechanisms for specifying XML schema Document Type Definition(DTD) Widely used XML Schema Newer,increasing use Database System Concepts-6th Edition 23.16 @Silberschatz,Korth and Sudarshan
Database System Concepts - 6 23.16 ©Silberschatz, Korth and Sudarshan th Edition XML Document Schema Database schemas constrain what information can be stored, and the data types of stored values XML documents are not required to have an associated schema However, schemas are very important for XML data exchange Otherwise, a site cannot automatically interpret data received from another site Two mechanisms for specifying XML schema Document Type Definition (DTD) Widely used XML Schema Newer, increasing use