SlideShare une entreprise Scribd logo
1  sur  23
Accessing XML Documents Using DOM


Objectives
In this lesson, you will learn to:
 Use XML DOM objects to perform the following tasks:
     Validate an XML document against an XML
      schema
     Provide user-selected view of data stored in an
      XML document




©NIIT                    eXtensible Markup Language/Lesson 8/Slide 1 of 23
Accessing XML Documents Using DOM


Problem Statement 8.D.1
 The head office of CyberShoppe receives data in the form of
 XML documents from its branches. In order to ensure
 consistency of data sent by the branches, the head office
 maintains the definitions for structures of documents in
 schemas. On receiving data from branches, the head office
 needs to verify that the data conforms to the schema for the
 respective documents. For this, they need to write a script,
 which validates the data stored in an XML document against
 a schema.




  ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 2 of 23
Accessing XML Documents Using DOM


Task List
 Identify a mechanism to validate an XML document
  against a schema.
 Identify the objects required to access an XML
  document through a scripting language.
 Write the code to validate an XML document against
  the schema.
 Execute the code.




©NIIT                 eXtensible Markup Language/Lesson 8/Slide 3 of 23
Accessing XML Documents Using DOM


Task 1: Identify a mechanism to validate an XML
document against a schema.
  In order to validate an XML document, you need to use a
  validating parser. MSXML is a DOM-based validating
  parser.
  Result
 You can use the XML DOM objects provided by MSXML in
  order to ensure that the structure of the XML document
  conforms to the schema.




  ©NIIT                 eXtensible Markup Language/Lesson 8/Slide 4 of 23
Accessing XML Documents Using DOM


Task 2: Identify the objects required to access an
XML document through a scripting language.
 You can use the DOMDocument object to load an XML
  document, parse it, and validate it.
 You can use the properties of IXMLDOMParseError
  object to display appropriate messages in case of an error.
 You require another object called XMLSchemaCache to
  load the schema document associated with the XML
  document.




   ©NIIT                 eXtensible Markup Language/Lesson 8/Slide 5 of 23
Accessing XML Documents Using DOM


Task 2: Identify the … scripting language.
(Contd.)
The XMLSchemaCache Object
 The XMLSchemaCache object is used to hold a
  collection of schema documents that specify the rules to
  which XML documents must conform.




 ©NIIT                 eXtensible Markup Language/Lesson 8/Slide 6 of 23
Accessing XML Documents Using DOM


 Task 2: Identify the … scripting language.
 (Contd.)
  The following table describes some methods provided
   by this object:
          Method                                         Description
add(namespaceURI, variable)    This method adds a new schema to the collection and also associates
                               the specified namespaceURI with the schema.


addCollection(XMLSchemaColle   This method adds schemas from other schema collections. It also
ction object)                  ensures that the namespaceURIs of the different schemas do not
                               clash.

get(namespaceURI)              This method returns a node that contains the schema element.



namespaceURI(index number)     This method returns the namespace that is associated with the
                               specified index number.

remove(namespaceURI)           This method removes a schema from the collection.




  ©NIIT                               eXtensible Markup Language/Lesson 8/Slide 7 of 23
Accessing XML Documents Using DOM


Task 2: Identify the … scripting language. (Contd.)
Result
 You can use the following XML DOM objects to validate
  the XML document against a schema:
     DOMDocument
     IXMLDOMParseError
     XMLSchemaCache




 ©NIIT                eXtensible Markup Language/Lesson 8/Slide 8 of 23
Accessing XML Documents Using DOM


Task 3: Write the code to validate the XML
document against the schema.
  To write a script that validates an XML document
  against the schema, you need to follow the steps given
  below:
 Create the user interface to accept the name of the XML
  document and the XML schema.
 Write the code to load the XML document.
 Write the code to add the XML schema in the
  XMLSchemaCache object.
 Write the code to validate the XML document against
  the schema.

 ©NIIT                 eXtensible Markup Language/Lesson 8/Slide 9 of 23
Accessing XML Documents Using DOM


Task 4: Execute the code.




 ©NIIT             eXtensible Markup Language/Lesson 8/Slide 10 of 23
Accessing XML Documents Using DOM


Just a Minute…
Write the code to add an XML schema called
“Products.xsd” to a schema collection.




 ©NIIT               eXtensible Markup Language/Lesson 8/Slide 11 of 23
Accessing XML Documents Using DOM


Problem Statement 8.D.2
 CyberShoppe sells its products through an e-commerce
 Web site. Details about the products sold at CyberShoppe
 need to be displayed. Product details include product name,
 description, price, and quantity for all products. A customer
 can choose to view the product details either as a table or
 as a bulleted list.




  ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 12 of 23
Accessing XML Documents Using DOM


Task List
 Identify a mechanism to access an XML document
  programmatically.
 Identify the objects required to apply the style sheet to
  the XML document during runtime.
 Create the XML document.
 Create the style sheets.
 Write the code to apply a style sheet dynamically to
  an XML document.
 Execute the code.



©NIIT                  eXtensible Markup Language/Lesson 8/Slide 13 of 23
Accessing XML Documents Using DOM


Task 1: Identify a mechanism to access an XML
document programmatically.
Result
  In this scenario, the customer can choose to view the
  product details as a table or as a list. Therefore, you require
  two style sheets. One of these style sheets needs to be
  applied to the XML document during runtime. Therefore,
  XML DOM can be used to access the XML document
  containing product details. You can also use XML DOM to
  dynamically apply an XSLT style sheet to an XML
  document.




  ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 14 of 23
Accessing XML Documents Using DOM

Task 2: Identify the objects required to apply the style
sheet to the XML document during runtime.
The XSLTemplate Object
 The XSLTemplate object is the DOM object that is used to
  access an XSLT style sheet.
 This object is used to hold a cached style sheet that can
  then be dynamically associated with an XML document.
 Before a style sheet document can be applied to an XML
  document, it is converted into a tree structure by the parser.
 The XSLT tree structure is loaded into the memory of the
  computer and used to process the XML document. This is
  because the XSLTemplate object stores the complied XSLT
  document. Therefore, you must first create an
  XSLTemplate object.

   ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 15 of 23
Accessing XML Documents Using DOM

Task 2: Identify the objects … runtime.(Contd.)
The XSLProcessor Object
 To process an XML document by using a style sheet, you
  must create an instance of the XSLProcessor object.
 This object is used to apply a style sheet to an XML
  document and then process that document.
 The XSLProcessor object is supported only in IE 5.0 and
  later.




   ©NIIT                 eXtensible Markup Language/Lesson 8/Slide 16 of 23
Accessing XML Documents Using DOM

Task 2: Identify the objects … runtime.(Contd.)
Result
  In the given scenario, the product details contained in the
  XML document need to be displayed either as a table or as a
  list by using an XSLT style sheet. This can be done using
  the XSLTemplate and XSLProcessor objects.




   ©NIIT                eXtensible Markup Language/Lesson 8/Slide 17 of 23
Accessing XML Documents Using DOM

Task 3: Create the XML document.


Task 4: Create the style sheets.


Task 5: Write the code to apply a style sheet
dynamically to an XML document.


Task 6: Execute the code.




   ©NIIT              eXtensible Markup Language/Lesson 8/Slide 18 of 23
Accessing XML Documents Using DOM


Just a Minute…
The following JavaScript code is used to create
XSLTemplate and DOMDocument objects. Identify the
errors in the code, if any.
custss= new
activexObject(MSXML.XSLTemplate.4)
custdomdoc=
activexobject( MSXML.ThreadedDOMdocument.4
.0);




 ©NIIT              eXtensible Markup Language/Lesson 8/Slide 19 of 23
Accessing XML Documents Using DOM


Just a Minute…
Identify the errors in the following JavaScript code:
xslProcObject.output=xmlDocObject;
xslProcObject.Transform
alert(xslProcObject);




  ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 20 of 23
Accessing XML Documents Using DOM


Problem Statement 8.P.1
 CyberShoppe sells books through an e-commerce Web site.
 A customer should be able to view book details, such as the
 name of the book, the first and last names of the author, the
 price, and the number of available books. A customer
 should be given the choice of viewing the book details either
 as a table or as a list. This choice is to be provided in a
 drop-down list. Also ensure that the XML document is
 loaded only once in the browser.
 Hint: You can create a global xmldoc variable and load the
 XML document in it. Use the OnLoad event of the BODY
 element to load the XML document.




  ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 21 of 23
Accessing XML Documents Using DOM

Summary
In this lesson, you learned that:
 The XMLSchemaCache object is used to associate an
  XML document with an XSD document.
 The XMLSchemaCache object is used to hold a collection
  of schema documents that specify the rules to which XML
  documents must conform.
 The XSLTemplate object is used to contain a compiled
  XSL document.
 The XSLProcessor object is used to apply style sheets on
  a given XML document.



  ©NIIT                  eXtensible Markup Language/Lesson 8/Slide 22 of 23
Accessing XML Documents Using DOM

Summary (Contd.)
 The XSLProcessor object is created using the
  createProcessor() method.
 The XSLProcessor object is associated with an XML
  document by using the input property of the XSLProcessor
  object.
 The XSLProcessor object provides the transform() method
  to transform an XML document according to the
  information provided in an XSLT style sheet.




  ©NIIT                eXtensible Markup Language/Lesson 8/Slide 23 of 23

Contenu connexe

Tendances

INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGProf Ansari
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOMSurinder Kaur
 
Tool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAMLTool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAMLNick Pruehs
 
Tool Development 04 - XML
Tool Development 04 - XMLTool Development 04 - XML
Tool Development 04 - XMLNick Pruehs
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02Terry Yoast
 
Java script
 Java script Java script
Java scriptbosybosy
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05Terry Yoast
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04Terry Yoast
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templatingbcruhl
 
R Tanenbaum .Net Portfolio
R Tanenbaum .Net PortfolioR Tanenbaum .Net Portfolio
R Tanenbaum .Net PortfolioRobert Tanenbaum
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based ApplicationsPrabu U
 
9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12Terry Yoast
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09Terry Yoast
 
Doctrine 2 - Introduction
Doctrine 2 - IntroductionDoctrine 2 - Introduction
Doctrine 2 - IntroductionDiego Lewin
 

Tendances (20)

INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
70 536
70 53670 536
70 536
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Tool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAMLTool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAML
 
Tool Development 04 - XML
Tool Development 04 - XMLTool Development 04 - XML
Tool Development 04 - XML
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
C#ppt
C#pptC#ppt
C#ppt
 
Java script
 Java script Java script
Java script
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
1204csharp
1204csharp1204csharp
1204csharp
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
R Tanenbaum .Net Portfolio
R Tanenbaum .Net PortfolioR Tanenbaum .Net Portfolio
R Tanenbaum .Net Portfolio
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based Applications
 
9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
LEARN C#
LEARN C#LEARN C#
LEARN C#
 
Doctrine 2 - Introduction
Doctrine 2 - IntroductionDoctrine 2 - Introduction
Doctrine 2 - Introduction
 

Similaire à 04 sm3 xml_xp_08

04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07Niit Care
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03Niit Care
 
03 sm3 xml_xp_05
03 sm3 xml_xp_0503 sm3 xml_xp_05
03 sm3 xml_xp_05Niit Care
 
Ado.net session13
Ado.net session13Ado.net session13
Ado.net session13Niit Care
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml dataaspnet123
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoftRaghu nath
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_javaardnetij
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.netglubox
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializingssusere19c741
 
epicenter2010 Open Xml
epicenter2010   Open Xmlepicenter2010   Open Xml
epicenter2010 Open XmlCraig Murphy
 
Javascript programming using the document object model
Javascript programming using the document object modelJavascript programming using the document object model
Javascript programming using the document object modelNicole Ryan
 
buildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptxbuildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptxNKannanCSE
 
Creating xml publisher documents with people code
Creating xml publisher documents with people codeCreating xml publisher documents with people code
Creating xml publisher documents with people codeRandall Groncki
 
Understanding Dom
Understanding DomUnderstanding Dom
Understanding DomLiquidHub
 

Similaire à 04 sm3 xml_xp_08 (20)

04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07
 
02 sm3 xml_xp_03
02 sm3 xml_xp_0302 sm3 xml_xp_03
02 sm3 xml_xp_03
 
03 sm3 xml_xp_05
03 sm3 xml_xp_0503 sm3 xml_xp_05
03 sm3 xml_xp_05
 
Ado.net session13
Ado.net session13Ado.net session13
Ado.net session13
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
 
XML
XMLXML
XML
 
Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
06 xml processing-in-.net
06 xml processing-in-.net06 xml processing-in-.net
06 xml processing-in-.net
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
 
treeview
treeviewtreeview
treeview
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Session 5
Session 5Session 5
Session 5
 
epicenter2010 Open Xml
epicenter2010   Open Xmlepicenter2010   Open Xml
epicenter2010 Open Xml
 
Javascript programming using the document object model
Javascript programming using the document object modelJavascript programming using the document object model
Javascript programming using the document object model
 
buildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptxbuildingxmlbasedapplications-180322042009.pptx
buildingxmlbasedapplications-180322042009.pptx
 
Session 4
Session 4Session 4
Session 4
 
Creating xml publisher documents with people code
Creating xml publisher documents with people codeCreating xml publisher documents with people code
Creating xml publisher documents with people code
 
Understanding Dom
Understanding DomUnderstanding Dom
Understanding Dom
 

Plus de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Dernier

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Dernier (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

04 sm3 xml_xp_08

  • 1. Accessing XML Documents Using DOM Objectives In this lesson, you will learn to: Use XML DOM objects to perform the following tasks: Validate an XML document against an XML schema Provide user-selected view of data stored in an XML document ©NIIT eXtensible Markup Language/Lesson 8/Slide 1 of 23
  • 2. Accessing XML Documents Using DOM Problem Statement 8.D.1 The head office of CyberShoppe receives data in the form of XML documents from its branches. In order to ensure consistency of data sent by the branches, the head office maintains the definitions for structures of documents in schemas. On receiving data from branches, the head office needs to verify that the data conforms to the schema for the respective documents. For this, they need to write a script, which validates the data stored in an XML document against a schema. ©NIIT eXtensible Markup Language/Lesson 8/Slide 2 of 23
  • 3. Accessing XML Documents Using DOM Task List Identify a mechanism to validate an XML document against a schema. Identify the objects required to access an XML document through a scripting language. Write the code to validate an XML document against the schema. Execute the code. ©NIIT eXtensible Markup Language/Lesson 8/Slide 3 of 23
  • 4. Accessing XML Documents Using DOM Task 1: Identify a mechanism to validate an XML document against a schema. In order to validate an XML document, you need to use a validating parser. MSXML is a DOM-based validating parser. Result You can use the XML DOM objects provided by MSXML in order to ensure that the structure of the XML document conforms to the schema. ©NIIT eXtensible Markup Language/Lesson 8/Slide 4 of 23
  • 5. Accessing XML Documents Using DOM Task 2: Identify the objects required to access an XML document through a scripting language. You can use the DOMDocument object to load an XML document, parse it, and validate it. You can use the properties of IXMLDOMParseError object to display appropriate messages in case of an error. You require another object called XMLSchemaCache to load the schema document associated with the XML document. ©NIIT eXtensible Markup Language/Lesson 8/Slide 5 of 23
  • 6. Accessing XML Documents Using DOM Task 2: Identify the … scripting language. (Contd.) The XMLSchemaCache Object The XMLSchemaCache object is used to hold a collection of schema documents that specify the rules to which XML documents must conform. ©NIIT eXtensible Markup Language/Lesson 8/Slide 6 of 23
  • 7. Accessing XML Documents Using DOM Task 2: Identify the … scripting language. (Contd.) The following table describes some methods provided by this object: Method Description add(namespaceURI, variable) This method adds a new schema to the collection and also associates the specified namespaceURI with the schema. addCollection(XMLSchemaColle This method adds schemas from other schema collections. It also ction object) ensures that the namespaceURIs of the different schemas do not clash. get(namespaceURI) This method returns a node that contains the schema element. namespaceURI(index number) This method returns the namespace that is associated with the specified index number. remove(namespaceURI) This method removes a schema from the collection. ©NIIT eXtensible Markup Language/Lesson 8/Slide 7 of 23
  • 8. Accessing XML Documents Using DOM Task 2: Identify the … scripting language. (Contd.) Result You can use the following XML DOM objects to validate the XML document against a schema: DOMDocument IXMLDOMParseError XMLSchemaCache ©NIIT eXtensible Markup Language/Lesson 8/Slide 8 of 23
  • 9. Accessing XML Documents Using DOM Task 3: Write the code to validate the XML document against the schema. To write a script that validates an XML document against the schema, you need to follow the steps given below: Create the user interface to accept the name of the XML document and the XML schema. Write the code to load the XML document. Write the code to add the XML schema in the XMLSchemaCache object. Write the code to validate the XML document against the schema. ©NIIT eXtensible Markup Language/Lesson 8/Slide 9 of 23
  • 10. Accessing XML Documents Using DOM Task 4: Execute the code. ©NIIT eXtensible Markup Language/Lesson 8/Slide 10 of 23
  • 11. Accessing XML Documents Using DOM Just a Minute… Write the code to add an XML schema called “Products.xsd” to a schema collection. ©NIIT eXtensible Markup Language/Lesson 8/Slide 11 of 23
  • 12. Accessing XML Documents Using DOM Problem Statement 8.D.2 CyberShoppe sells its products through an e-commerce Web site. Details about the products sold at CyberShoppe need to be displayed. Product details include product name, description, price, and quantity for all products. A customer can choose to view the product details either as a table or as a bulleted list. ©NIIT eXtensible Markup Language/Lesson 8/Slide 12 of 23
  • 13. Accessing XML Documents Using DOM Task List Identify a mechanism to access an XML document programmatically. Identify the objects required to apply the style sheet to the XML document during runtime. Create the XML document. Create the style sheets. Write the code to apply a style sheet dynamically to an XML document. Execute the code. ©NIIT eXtensible Markup Language/Lesson 8/Slide 13 of 23
  • 14. Accessing XML Documents Using DOM Task 1: Identify a mechanism to access an XML document programmatically. Result In this scenario, the customer can choose to view the product details as a table or as a list. Therefore, you require two style sheets. One of these style sheets needs to be applied to the XML document during runtime. Therefore, XML DOM can be used to access the XML document containing product details. You can also use XML DOM to dynamically apply an XSLT style sheet to an XML document. ©NIIT eXtensible Markup Language/Lesson 8/Slide 14 of 23
  • 15. Accessing XML Documents Using DOM Task 2: Identify the objects required to apply the style sheet to the XML document during runtime. The XSLTemplate Object The XSLTemplate object is the DOM object that is used to access an XSLT style sheet. This object is used to hold a cached style sheet that can then be dynamically associated with an XML document. Before a style sheet document can be applied to an XML document, it is converted into a tree structure by the parser. The XSLT tree structure is loaded into the memory of the computer and used to process the XML document. This is because the XSLTemplate object stores the complied XSLT document. Therefore, you must first create an XSLTemplate object. ©NIIT eXtensible Markup Language/Lesson 8/Slide 15 of 23
  • 16. Accessing XML Documents Using DOM Task 2: Identify the objects … runtime.(Contd.) The XSLProcessor Object To process an XML document by using a style sheet, you must create an instance of the XSLProcessor object. This object is used to apply a style sheet to an XML document and then process that document. The XSLProcessor object is supported only in IE 5.0 and later. ©NIIT eXtensible Markup Language/Lesson 8/Slide 16 of 23
  • 17. Accessing XML Documents Using DOM Task 2: Identify the objects … runtime.(Contd.) Result In the given scenario, the product details contained in the XML document need to be displayed either as a table or as a list by using an XSLT style sheet. This can be done using the XSLTemplate and XSLProcessor objects. ©NIIT eXtensible Markup Language/Lesson 8/Slide 17 of 23
  • 18. Accessing XML Documents Using DOM Task 3: Create the XML document. Task 4: Create the style sheets. Task 5: Write the code to apply a style sheet dynamically to an XML document. Task 6: Execute the code. ©NIIT eXtensible Markup Language/Lesson 8/Slide 18 of 23
  • 19. Accessing XML Documents Using DOM Just a Minute… The following JavaScript code is used to create XSLTemplate and DOMDocument objects. Identify the errors in the code, if any. custss= new activexObject(MSXML.XSLTemplate.4) custdomdoc= activexobject( MSXML.ThreadedDOMdocument.4 .0); ©NIIT eXtensible Markup Language/Lesson 8/Slide 19 of 23
  • 20. Accessing XML Documents Using DOM Just a Minute… Identify the errors in the following JavaScript code: xslProcObject.output=xmlDocObject; xslProcObject.Transform alert(xslProcObject); ©NIIT eXtensible Markup Language/Lesson 8/Slide 20 of 23
  • 21. Accessing XML Documents Using DOM Problem Statement 8.P.1 CyberShoppe sells books through an e-commerce Web site. A customer should be able to view book details, such as the name of the book, the first and last names of the author, the price, and the number of available books. A customer should be given the choice of viewing the book details either as a table or as a list. This choice is to be provided in a drop-down list. Also ensure that the XML document is loaded only once in the browser. Hint: You can create a global xmldoc variable and load the XML document in it. Use the OnLoad event of the BODY element to load the XML document. ©NIIT eXtensible Markup Language/Lesson 8/Slide 21 of 23
  • 22. Accessing XML Documents Using DOM Summary In this lesson, you learned that: The XMLSchemaCache object is used to associate an XML document with an XSD document. The XMLSchemaCache object is used to hold a collection of schema documents that specify the rules to which XML documents must conform. The XSLTemplate object is used to contain a compiled XSL document. The XSLProcessor object is used to apply style sheets on a given XML document. ©NIIT eXtensible Markup Language/Lesson 8/Slide 22 of 23
  • 23. Accessing XML Documents Using DOM Summary (Contd.) The XSLProcessor object is created using the createProcessor() method. The XSLProcessor object is associated with an XML document by using the input property of the XSLProcessor object. The XSLProcessor object provides the transform() method to transform an XML document according to the information provided in an XSLT style sheet. ©NIIT eXtensible Markup Language/Lesson 8/Slide 23 of 23