Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 1 XML & Related Languages Unit 2 XML Essentials (part 2)

Similar presentations


Presentation on theme: "XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 1 XML & Related Languages Unit 2 XML Essentials (part 2)"— Presentation transcript:

1 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 1 XML & Related Languages Unit 2 XML Essentials (part 2)

2 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 2 In Unit 1, we looked at… XML document  Structured data in text format  Elements  Attributes  Must be well-formed

3 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 3 In Unit 2… DTDs  Document Type Definitions  Letting us specify a document structure  for a particular use  part of the eXtensibility of XML Validation  Does a document conform to our structure?  Compare to well-formed Namespaces  Preventing naming conflicts and confusion

4 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 4 DTDs Document Type Definitions  Define the legal structure of an XML Document… … for a particular application  Goes above and beyond being well-formed  Describes structure, content, and quantities of  Elements  Attributes  Entities

5 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 5 DTDs (part 2) Allow verification that a particular XML document is consistent with a known specification Independent developers sharing a DTD will know that their XML documents are consistent and compatible (i.e., share the same data structure) Enable validation

6 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 6 DTDs (part 3) DTDs are different from XML Schema  Older  More widely used today XML Schema are the W3C recommended replacement for DTDs  New development should probably use XML Schema  Understanding DTDs will make understanding XML Schema much easier

7 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 7 DTDs & Validation XML parser  Reads content of XML document  Reports error if not well-formed Validating parser  XML parser and  Validates an XML document against its related DTD (or XML schema)  Reports an error if an inconsistency occurs

8 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 8 Declaring a DTD For an XML document to be validated with respect to a DTD, the document must declare its DTD  Part of the prolog to the XML document  Inline  DTD is fully defined in the XML document itself  External reference  External reference to the DTD itself (URL)  More useful: they can be shared across apps

9 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 9 Inline DTD ]> Note that the type being declared (rootElement)  must match the root element of the document  must be declared as an element in the DTD

10 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 10 External DTD Reference Public reference  Provide information about the owner of the DTD spec (e.g., W3C)  Provide location of DTD Non-public reference  Provide location of DTD only

11 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 11 External DTD Reference – Public <!DOCTYPE rootElement PUBLIC "ownerString" "locationString" > Note that the type being declared (rootElement)  must match the root element of the document  must be declared as an element in the DTD

12 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 12 External DTD Reference – Public Example: SVG file <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> Owner String structure  separates categories with //  + or – tells whether it's a recognized standard (e.g., ISO)  Organization  Descriptive label  Language code (ISO 639-1)

13 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 13 External DTD Reference – Non-Public <!DOCTYPE rootElement SYSTEM "locationString" > Note that the type being declared (rootElement)  must match the root element of the document  must be declared as an element in the DTD

14 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 14 External DTD Reference – Non-Public Example: our own Document Type Location String  Note: Validation requires access to the file in this string  Not just a unique string like a namespace (that we'll see later)  URL: fully qualified or relative  File: relative to current directory

15 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 15 DTDs: On with the Show You'll notice…  DTDs are not defined in XML syntax  XML Schemas are  DTDs are not that easy to read  But you can get the hang of it  Most browsers don't use their parsers as validating parsers  To check our results, we really should use a program that calls a validating parse »Ex: a tool like XmlSpy

16 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 16 DTD: Element Declarations Establishes a valid element name Describes what the element can contain  elementName: tag that will be used  elementContent: name(s) of allowed child element(s) in parentheses (more in a bit)

17 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 17 DTD Element Declaration Example contains exactly 1 name element followed by exactly 1 city element followed any number of player elements (note the * meaning 0 or more)  Note that this enforces ordering and quantity of the elements that are contained,, and contain only text (#PCDATA). They cannot contain other elements.

18 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 18 DTD: Elements  #PCDATA PCDATA  parsed character data  #PCDATA is a reserved token in DTDs to mean that an element contains character text  0 or more characters  Boston »Boston is the character text   Since there's no element name in the parentheses, can only contain the parsed character data.  Other elements would not be allowed

19 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 19 DTD: Elements  element content Specified in parentheses  What elements (if any) are allowed  Order of the elements  Quantity of each element Which elements are allowed?  Only those element names listed  and all of those listed must be defined as elements in the DTD

20 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 20 DTD: Elements  element content (part 2) Order of contained elements  If you want to specify the exact order in which they appear…  Separate by commas »Ex: (name, city) Quantity of each element  element  exactly once  element+  1 or more times  element?  0 or 1 time  element*  0 or more times

21 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 21 DTD: Elements  choices & parentheses Sometimes, you want to provide a choice between alternatives that can be contained by an element…  Vertical bar (|) – like a logical ‘exclusive or’ or  Can't repeat an element in the choice

22 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 22 DTD: Elements  choices & parentheses Can use additional parentheses to show additional groupings and/or choices  Exactly 1 Orange element, followed by  0 or 1 Grapefruit elements, followed by  1 or more additional elements (where each additional element is either an Apple element or an Orange element)

23 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 23 DTD: Elements  mixed-content elements Mixed-content elements can contain character data and other elements DTD doesn't allow complete freedom in design of mixed content:  Use #PCDATA at the beginning of a group  Indicating a choice between #PCDATA and 1 or more elements that can be contained in the element  Make sure the group is declared as having 0 or more cardinality (*)

24 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 24 DTD: Elements  mixed-content elements can contain parsed character data, elements, and elements  in any order  can't specify how many of each  can't specify order in which they appear

25 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 25 DTD: Elements  empty & any Empty element  element can appear but must be empty  Contains neither elements nor character data Element that can contain anything  Still needs to be well-formed  Can be useful for holding XML for which you don't have the DTD or for which you haven't finished the DTD

26 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 26 DTD: Attribute List Declarations Define:  Which attributes can appear in an element's start- tag  Type of the attribute (in a limited sense)  Whether the attribute is required and/or default values

27 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 27 DTD:Attributes  names Must be legal attributes names Any number of attributes…  But each name must be unique for the element Order of declaration doesn't matter  Since order they appear in XML doesn't matter

28 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 28 DTD:Attributes  types Used to restrict values of attributes  10 types  4 most commonly used  CDATA  Any legal XML character data  NMTOKEN  Contains only characters in a legal XML name. Used to prevent whitespace.  ID  Legal XML name and unique within the document for this element/attribute in this document. Like a key.  enumerated  Specific list of values in parentheses separated by |

29 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 29 DTD:Attributes  required/default 4 choices to indicate whether attribute is required and/or default value  #REQUIRED  Attribute must be included in the element's start tag. Use its value.  #IMPLIED  Attribute is optional. No default value.  #FIXEDliteral  Attribute is optional. If in element start-tag, value must match literal. If not in start-tag, value is assumed to be literal.  literal  Attribute is optional. If not in start- tag, value defaults to literal

30 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 30 DTD:Attributes – An Example <!ATTLIST Employee Badge ID #REQUIRED WorkLocation CDATA "HOP1" PayType ( Salary | Hourly | Contract ) #REQUIRED> These are the attributes allowed for Employee elements  The Badge attribute has type ID and is required  The WorkLocation attribute allows any string data, is optional, and has a default value of “HOP1”  The PayType attribute value must be either “Salary”, “Hourly”, or “Contract” and the attribute is required.

31 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 31 DTD: Entities Remember the 5 built-in entity references? (ex: > and &) DTDs let you define your own  Then, you can use them in your documents  Like macros that expand to a particular value

32 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 32 DTD: Entities (part 2) Example definition (in.dtd) 2002 John Arnold "> Example use (in.xml) &copyright;

33 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 33 DTD: Entities  External Entities Let you define an entity in another file  Like an include (text replacement)  If it contains markup, it must be well-formed  Need to be able to access it!  Usage is the same: &extCopyright;

34 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 34 DTD: Entities  Parameter Entities Internal and External forms Are used only within the DTD itself  Text that's repeated throughout the DTD that you don't want to have to retype in multiple places  Additional syntax: % Internal: External:

35 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 35 DTD: Entities  Parameter Entities Example definition (in.dtd) Example use (in.dtd) Note: Can't use in the.xml file that refers to.dtd!

36 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 36 DTD Example Goal: XML representation for employees  There are 0 or more employees  Each employee has the following:  First Name  Last Name  Badge Number »must be unique  Job Code and description: »Code might be all numeric  Pay type »Salary, Hourly, or Contract  Work location: »optional. If not given, assume "HOP1"

37 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 37 DTD Example (part 2) Questions to ask ourselves given the requirements  Elements vs attributes  What can we model with DTDs and what can't we model? Start with root element and elements it might contain

38 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 38 DTD Example (part 3) Employee has first and last name Badge needs to be unique  Hmmm… sounds like a job for an ID attribute Job Code and Description  Sounds like an element with an attribute might work here Pay type  3 "legal" values. Sounds like we might need an enumerated attribute Work location has an optional value  Another place where an attribute might work best

39 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 39 DTD Example (part 4) Add the other elements we need  Remember every element you refer to must be declared

40 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 40 DTD Example (part 5) Add the attributes we need <!ATTLIST Employee Badge ID #REQUIRED WorkLocation CDATA "HOP1" PayType ( Salary | Hourly | Contract ) #REQUIRED>

41 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 41 DTD Example (part 6) Connecting the XML Document to the DTD  … with a DOCTYPE in the XML Prolog John Doe Software Engineer Jane Smith Dir. of Engineering

42 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 42 DTD Example (part 7) Validating the XML Document  Just because we added the DOCTYPE doesn’t mean it’s valid!  DOCTYPE provides the association and location of the DTD  A Validating parser (or equivalent tool) is needed to actually determine if the XML document is valid

43 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 43 Namespaces in XML A W3C Recommendation after XML 1.0  Namespaces in XML, Jan. 1999  http://www.w3.org/TR/REC-xml-names/  Therefore, the oldest parts of XML were designed before the work on namespaces was finished  DTDs, etc.  Newer parts of XML (e.g., XSLT, XPath, XML Schema) fully integrate with namespaces

44 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 44 Why Namespaces? What if… (#1)  I define the name element like this: John E Arnold  … but you define it like this: John E Arnold

45 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 45 Why Namespaces? (part 2) If I am going to define a structure that uses a name element, which would I expect to encounter?  Do I need to be prepared for both?  Can I specify which one I want to allow? Use namespaces to differentiate!

46 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 46 Why Namespaces? (part 3) What if… (#2)  We need to integrate our application (employee info) with a system management application that defines its data with this: qa.MyCompany.com test01 John E. Arnold

47 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 47 Why Namespaces? (part 4) What if… (#2 continued)  Can we define our document to allow only the 'hardware' form of name in one place and only the 'person' form of name in the other? Use namespaces to differentiate!

48 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 48 Namespaces Allow you to divide your structure into application-specific groups  Ex: This data came from (or is destined for) the employee application Allow you to resolve collisions that arise from 2 designers using the same name for different data  Ex: This data is structured using the definition from the system management application

49 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 49 Namespaces (p. 2) Without namespaces  Elements defined (and compared and validated) in terms of their name =  The same as having an empty string as its namespace (the ‘no namespace’ namespace) With namespaces  Elements defined (and compared and validated) in terms of namespace and name = ???

50 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 50 Namespaces (p. 3) Q: Are these two elements ‘equal’ ??? = A: It depends…  The element names (to the right of the colon) must be identical  The namespaces must be identical, too.  But… the string to the left of the colon is an alias for a namespace and not the namespace itself!

51 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 51 Namespaces: Example <qaLabResponsibilities xmlns:hw="http://www.brandeis.edu/XmlCourse/hardware" xmlns:people="http://www.brandeis.edu/XmlCourse/roster"> qa.MyCompany.com test01 John E. Arnold

52 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 52 Namespace: Uniqueness Namespaces are strings. Any element or attribute with the same name in the same namespace should be referring to an element or attribute of the same ‘type’  Same structure, same semantics, etc. Namespace names refer to data that is structured for one purpose or application  Collisions can occur unless you are absolutely certain that the name of your namespace will not used to model any other reason  The same namespace can be (and is) used in multiple documents…  But the name we choose should always refer to the same data structuring

53 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 53 Namespace: Uniqueness (part 2) Use unique URI (uniform resource indicator) for namespace names  Ex:http://www.brandeis.edu/XmlCourse/hw mailto:jarnold@brandeis.edu Best practice  Use a domain you own  Add on unique identifier for each use

54 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 54 Namespace: Uniqueness (part 3) Use of URIs does not mean that you need to be connected to the network!  They're really just unique strings  Don't assume that there really is a web page that is associated with the URI  It's just a convenient string that minimizes chance of reuse  Not like external DTD declarations that must be accessible in order to work

55 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 55 Declaring Namespaces To use a namespace, you need to declare it  Declare it like an attribute (in the start tag) using one of 2 forms  xmlns  declares a default namespace  xmlns:alias  declares a namespace alias  Can declare a namespace in any element in an XML document  Scoping rule:  Namespace is declared only in the element in which it is declared and its descendants

56 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 56 Declaring Namespaces (p. 2) Declaring without an alias: Gregory Brill CodeNotes for XML CodeNotes for.NET CodeNotes for Java  Declares a default namespace

57 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 57 Declaring Namespaces (p. 3) Default namespace  There is no alias with which you can refer to the namespace  The element in which the default namespace is declared is put into the default namespace  Unless the element is explicitly defined as being in another namespace (using an alias)

58 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 58 Declaring Namespaces (p. 4) Declaring with an alias: John Arnold Jane Doe John Smith  Defines a namespace alias  Can declare more than one alias in an element’s start tag

59 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 59 Declaring Namespaces (p. 5) Namespace alias  Declares a short name that can be used to refer to the namespace  The alias is used to the left of the colon to put an element (or attribute) into the associated namespace contents of the element  Refers to an element named ElementA in the namespace associated with the NS1 alias  The namespace is the full string, not the alias string!  Two different alias strings can resolve to the same namespace string  Sometimes and can refer to the same element in the same namespace!

60 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 60 Declaring Namespaces (p. 6) Namespace alias (continued)  Unlike a default namespace, the declaration of an alias does not assign that namespace to the element in which the alias is declared  The declaration makes it eligible for use…  … it does not automatically put it into use is not the same as

61 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 61 Declaring Namespaces (p. 7) Why allow use of alias as a prefix?  Less typing (since the actual namespace string can be quite long)  Some characters in the namespace aren’t allowed in XML tag names  …But remember the key difference  … a namespace with an alias doesn't get used until you prefix an element (or attribute) with it  Thus, declaring a namespace prefix in an Element definition does not mean that Element is automatically in the namespace (see use of myNS in previous example) Once an element is in a namespace, what about its child elements?

62 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 62 Namespace Declaration ‘Inheritance’ Namespace declarations are ‘inherited’  Apply to the element in which they are defined and to all elements within the content of that element  Exception 1: an alias can be redefined to a different namespace in a child element by re-using the alias in a namespace declaration  Exception 2: a default namespace can be changed in a descendant element by redefining the default namespace Ramifications  Once declared, a namespace alias can be used to be put any child elements or their attributes into the namespace  Once a default namespace is declared, all descendant elements will be put into that default namespace unless (a) the element is prefixed with a namespace alias or (b) the default namespace is overridden with a new default namespace

63 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 63 Namespace Declaration ‘Inheritance’ (p. 2) John E Arnold 2003 Continuing Studies Instructor

64 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 64 Namespace Declaration ‘Inheritance’ (p. 3) Namespace declaration ‘inheritance’ is a relationship between elements, not attributes! Attributes are not in a namespace (that is, their namespace string is empty) unless the attribute name is prefixed with a namespace alias and a colon Thomas

65 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 65 A Namespace Example some character data More character data outside, middle, and inside are in the default namespace core is in the inner namespace myAttr is not in either namespace – it's an attribute without an explicitly specified namespace

66 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 66 Using A Namespace Alias Once you've declared a namespace alias, you associate an element (or attribute) with that namespace by using prefix:  Result is a qualified name Use of prefix in start-tag requires use of prefix in end-tag.  2 identical element names in different namespaces are considered different elements

67 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 67 Another Namespace Example <Instrumentation xmlns="urn:myInstruments" xmlns:prop="urn:myProperties" xmlns:uom="urn:myUnitsOfMeasure"> 46 47 95,,, and are in the default namespace ( "urn:myInstruments" ) and are in the urn:myProperties namespace The units attributes are in the urn:myUnitsOfMeasure namespace

68 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 68 Namespaces with Attributes As previously discussed, attributes can be assigned a namespace, too.  But namespaces for attributes need to be explicitly specified. The 'Namespaces in XML' W3C Recommendation says:  "The namespace declaration is considered to apply to the element where it is specified and to all elements within the context of that element, unless it is overridden by another namespace declaration…"  "A default namespace is considered to apply to the element where it is declared (if that element has no namespace prefix), and to all elements with no prefix within the content of that element."  "Note that default namespaces do not apply directly to attributes."  The DOM Level 2 spec says:  Note: Per the Namespaces in XML Specification [Namespaces] an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.

69 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 69 Namespaces with Attributes (part 2)  The examples in the recommendation also indicate that attributes are not automatically put in the same namespace as the element for which the attribute is specified  "[…] each of the following is legal because the default namespace does not apply to attribute names."

70 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 70 Namespaces with Attributes (part 3)  "Because attributes must be unique on a per element basis, you rarely need to assign namespaces to attributes" (XML Pocket Consultant, p. 97)  But: some XML applications define attributes that are expected to be in a particular namespace  Ex: for validation against a range of values  If you need to do this, you use the same syntax as assigning a namespace to an element: prefix:attributeName

71 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 71 When will namespaces matter? When we move to validation of XML When we write code that is looking for particular elements and/or attributes that are in a given namespace (i.e, soon)

72 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 72 Namespaces: Reminder Declaring a namespace prefix (xmlns:???) does not assign that namespace to the element in which the namespace is declared This is my catalog. is not the same thing as This is my catalog.

73 XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 73 Unit 3… Begin looking at ways XML can be transformed  To convert from one representation to another  Data transformation  Output/Presentation transformation  First stop: XSLT and XPath  These will use namespaces!


Download ppt "XML & Related LanguagesXML Essentials (part 2) © 2003 John E. Arnold All Rights Reserved. 1 XML & Related Languages Unit 2 XML Essentials (part 2)"

Similar presentations


Ads by Google