Attributes Elements can have attributes <account acct-.type=“checking”> <account number>A-102 </account number> <branch name>Perryridge </branch_name> <balance>400 </balance> </account> 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 <account acct-type=“checking”monthly-fee=“5"> Database System Concepts-5th Edition,Aug 22,2005. 10.12 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.12 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. Attributes Elements can have attributes <account acct-type = “checking” > <account_number> A-102 </account_number> <branch_name> Perryridge </branch_name> <balance> 400 </balance> </account> 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 <account acct-type = “checking” monthly-fee=“5”>
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 <account account number="A-101">....</account> <account> <account number>A-101</account number>... </account> Suggestion:use attributes for identifiers of elements,and use subelements for contents Database System Concepts-5th Edition,Aug 22,2005. 10.13 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.13 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. 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 – <account account_number = “A-101”> …. </account> – <account> <account_number>A-101</account_number> … </account> 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 <bank XmIns:FB='http://www.FirstBank.com'> <FB:branch> <FB:branchname>Downtown</FB:branchname> <FB:branchcity>Brooklyn </FB:branchcity> </FB:branch> </bank> Database System Concepts-5th Edition,Aug 22,2005. 10.14 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.14 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. 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 <bank Xmlns:FB=‘http://www.FirstBank.com’> … <FB:branch> <FB:branchname>Downtown</FB:branchname> <FB:branchcity> Brooklyn </FB:branchcity> </FB:branch> … </bank>
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 <account number=:“A-101"branch=“Perryridge”balance=“200/> To store string data that may contain tags,without the tags being interpreted as subelements,use CDATA as below <![CDATA[<account>...</account>]]> Here,<account>and </account>are treated as just strings CDATA stands for "character data Database System Concepts-5th Edition,Aug 22,2005. 10.15 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.15 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. 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 <account number=“A-101” branch=“Perryridge” balance=“200 /> To store string data that may contain tags, without the tags being interpreted as subelements, use CDATA as below <![CDATA[<account> … </account>]]> Here, <account> and </account> 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-5th Edition,Aug 22,2005. 10.16 ©Silberschat乜,Korth and Sudarshan
Database System Concepts - 5 10.16 ©Silberschatz, Korth and Sudarshan th Edition, Aug 22, 2005. 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