SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
XML DOM Functionality in .NET
DSK Chakravarthy
http://dskc.blogspot.com
dskcheck@msn.com
http://msmvps.com/blogs/Chakravarthy
Intro to XML DOM
Reading XML Data

Agenda

Working with Nodes
xPath Expressions
Q&A
Contact ME

• You can see the agenda along the
entire presentation
• Q&A is at the End of session
Intro to XML DOM
Reading XML Data

What I talk about

Working with Nodes
xPath Expressions
Q&A
Contact ME

• The basics of reading and writing
XML, programmatically
• The important classes associated
with XML documents in the
System.XML namespace
• How to Read XML Data
• How to Traverse in XML DOM
using xPath expressions
Intro to XML DOM

Are you ready ?

Reading XML Data
Working with Nodes
xPath Expressions
Q&A
Contact ME

Prerequisites
•Basic Understanding of XML
•Ability to read code
Intro to XML DOM
Reading XML Data

Introduction to XML DOM

Getting Started

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Many apps need to read/write XML
data
• Perhaps need to:
– Store or retrieve configuration settings
– Read/write data stored in XML format
– Handle inter-application data transfer

• XML programming required for all
these
• System.Xml.XmlDocument class
provides support for handling XML
Intro to XML DOM
Reading XML Data

Introduction to XML DOM

What I’ll cover now

Working with Nodes
xPath Expressions
Q&A
Contact ME

• NET Framework uses XML in many
ways
– Provides several techniques for working with
XML

• Only cover tree-based, in-memory
handling
• Other sessions cover other techniques,
including the XmlReader/XmlWriter
classes
Intro to XML DOM
Reading XML Data

Introduction to XML DOM

.NET APIs for working with XML

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Two main .NET APIs for working
with XML:
– Cached, read/write, random access
• XML Document Object Model (DOM)
• Tree-based, in-memory cache
• Represented by the XmlDocument class

– Non-cached, forward-only, read-only
access
• Represented by the XmlReader/XmlWriter
classes
Intro to XML DOM
Reading XML Data

Introduction to XML DOM
Tree-Based XML Handling

1/4

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Using this API, XML data loaded
synchronously into a “tree”
– Contains root node, and multiple child
nodes
– Each XML element corresponds to
one or more nodes in the tree
– Each node (except root node) has a
parent node
– Each node (except root node) can
have multiple siblings
– Each node can have multiple children
Intro to XML DOM
Reading XML Data

Introduction to XML DOM
Tree-Based XML Handling

2/4

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Data loaded into memory
– Provides random access to individual
nodes
– Can search for any node, at will

• Tree-based structure represents
XML infoset
– This is the data stored in the
serialized XML format
– API doesn’t care about angle brackets
and quotes
• Just the data and its relationships
Intro to XML DOM
Reading XML Data

Introduction to XML DOM
Tree-Based XML Handling

3/4

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Turns this XML content:
<bookstore>
<book genre="novel" publicationdate="1997"
ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
</bookstore>
Intro to XML DOM
Reading XML Data

Introduction to XML DOM
Tree-Based XML Handling

Working with Nodes
xPath Expressions
Q&A

• Into this data structure
bookstore

Contact ME

book
publication date
publication date

publication date
title
author
firstname
lastname
price

4/4
Intro to XML DOM
Reading XML Data

Introduction to XML DOM

Non-Cached XML Handling

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Allows for fast access
– No waiting for data to load

• Requires less overhead
• Doesn’t allow random access to
data
– Data flows to application in the order it
appears within the original XML
stream

• Not covered here
Intro to XML DOM
Reading XML Data

Introduction to XML DOM

What is XML DOM?

Working with Nodes
xPath Expressions
Q&A
Contact ME

• To provide standard mechanism for
programmatically working with data
– W3C proposed a standard API for working
with XML
– XML Document Object Model is the result
• Provides software vendors with API for
manipulating XML data

• Before .NET, VB developers used
MSXML COM component
– Now use System.Xml namespace
Demonstaration -- 0
investigating a sample file – Grocery store
Intro to XML DOM

Introduction to XML DOM

Sample file as Datastructure

Reading XML Data
Working with Nodes

Grocery Store

xPath Expressions

departments

Q&A
Contact ME

department

department

Name = “Fruits”

Name = “Breads”

#text
Brain’s Groceries

Item

Item
Id=“B1”

Store name

Name

Id=“F1”

Name

#text
Wonder Bread

Item

Type = “Muffin”

Id=“B2”

Name
#text
Blueberry Muffin

#text
Apple

Price

Price

Price
#text
3.99

#text
1.29

New

New

#text
0.99
Intro to XML DOM
Reading XML Data

Reading XML Data

Load XML Data

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Need to load XML data into an
XmlDocument object
– Parse persisted XML into tree-based
structure in memory

• Create instance of XmlDocument object
• Call Load method, providing file name
– Other alternative means for loading, as well

• Work with data in tree-based format
• Retrieve OuterXml property to view XML
Intro to XML DOM
Reading XML Data

Reading XML Data

Working with Node’s children

1/2

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Calling Load method fills data structure
– Single root element, possibly other nodes

• Sample root node contains three children
– XML declaration (processing instruction)
– Comment
– GroceryStore document element

• XmlDocument inherits from XmlNode
class
– Document == root node

• Use HasChildNodes and ChildNodes
Intro to XML DOM
Reading XML Data

Reading XML Data

Working with Node’s children

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Interesting issues:
– No recursion
• Just displays information about the
immediate children of selected node

– Name properties differ
• xml, #comment, #text, real names

– Checking HasChildNodes is
redundant
• If your intent is to iterate through the
nodes

2/2
Demonstaration -- 1
Load XML Data
Child Nodes
Visit All Nodes
Elements By Name
Text Nodes
Intro to XML DOM
Reading XML Data

Working with Nodes

Retrieve nodes matching Criteria

Working with Nodes
xPath Expressions
Q&A
Contact ME

• GetElementsByTagName works
well, but limited
• For more general criteria, use
SelectNodes or SelectSingleNode
methods of XmlNode
• Can pass XPath query
– XPath is powerful, and complex
– Can only touch on it here
Intro to XML DOM
Reading XML Data

Working with Nodes

Getting started with xPath

1/2

Working with Nodes
xPath Expressions
Q&A
Contact ME

• xPath expressions "know" where to
start looking, based on object
whose method you call
• Use "//" separator to indicate what
follows is a descendant, at any
level
• Use "/" separator to indicate what
follows is a direct descendant
Intro to XML DOM
Reading XML Data

Working with Nodes

Getting started with xPath

2/2

Working with Nodes
xPath Expressions
Q&A
Contact ME

• For example:
– //Department//Name
• Looks within Department node (at any
lower level) for Name (at any level below
Department)

• Use "*" to look for any element
name
• To match root node of starting
object, simply list the name
Intro to XML DOM
Reading XML Data

Working with nodes
More about XPATH

1/2

Working with Nodes
xPath Expressions
Q&A
Contact ME

• To match existence of a child
node,
– use: //Item[New]/Name
• Looks for Item that contains a New
element, then matches Name element of
the Item

• To match existence of an attribute,
use:
– //Item[@Type]
• Looks for a Department node with a
Name attribute
Intro to XML DOM
Reading XML Data

Working with nodes
More about XPATH

2/2

Working with Nodes
xPath Expressions
Q&A

• To match specific values, use:
– //Department[@Name= 'Fruits']

Contact ME

• Once you have the XPath
expression, and the retrieved
node list, iterate through
nodes
Intro to XML DOM
Reading XML Data

Working with nodes

Reference to specific Node

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Use XmlNode.SelectSingleNode
method
• Retrieves reference to first
matching node
• Best when:
– You know there 's only one match
– You actually want a relative (parent?)
of the node you find
Demonstaration -- 2
Select Nodes
Select Single Node
Find Relatives
Intro to XML DOM
Reading XML Data

Working with nodes

Retrieve Node attributes

Working with Nodes
xPath Expressions
Q&A
Contact ME

• XmlNode.Attributes property retrieves
XmlAttributeCollection object
• Collection of XmlAttribute objects
– Nodes with a name, and a value

• If you just want a single attribute
– Use GetNamedItem method of Attributes
collection

• Display all department names?
– Name is an attribute of Department element
Demonstaration -- 3
Retrieve Attributes
Single Attribute
Intro to XML DOM

XmlDocument

Conclusion

Reading XML Data
Working with Nodes
xPath Expressions
Q&A
Contact ME

• Derived from the XmlNode class
• Represents an entire (in memory) XML
document
• Supports DOM Level 1 and Level 2 Core
functionality
• Reading & writing built on top of XmlReader
& XmlWriter
• Load a document and generate the DOM
– Using: URI, file, XmlReader, XmlTextReader or
Stream
Intro to XML DOM
Reading XML Data

Summary

Working with Nodes
xPath Expressions
Q&A
Contact ME

• In this session, we looked into:
– How to load XML data into memory,
using the XmlDocument class
– How to read through XML data
• retrieving elements by name
• by using XPATH
• by relative path

– How to deal with node attributes
Intro to XML DOM
Reading XML Data

Questions ?

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Request you to drop me a line
• Doesn’t mean that you forget
to post them at B.NET
• You can expect reply from
both mail & at the discussion
thread
Intro to XML DOM
Reading XML Data
Working with Nodes
xPath Expressions
Q&A
Contact ME

The Webcast Quiz!
• Four questions, multiple choice type
– More than one maybe correct

• Two lucky winners will win an
Orchid Music Player
• If you participate in the contest and
are among the 2 lucky winners, your
name will be featured on
http://www.microsoft.com/india/web
casts/
Intro to XML DOM
Reading XML Data
Working with Nodes

1. What are the key themes in the Data
Platform track at TechEd 2006
India?

xPath Expressions
Q&A
Contact ME

A) Programming,
Database
Management and
BI

B) Service Oriented
Architecture and
Robust Data
Management

C) Integrated
D) Future of
Solution Scenarios Computing and
role of real-world
Data Management
Intelligence
Intro to XML DOM
Reading XML Data

2. Select 3 core themes under Data
Management at Tech.Ed 2006 India.

Working with Nodes
xPath Expressions
Q&A

A) Security

B) Monitoring and
Analysis

C) Scalability

D) Robust
integration of
Development Tools
and RDBMS

Contact ME
Intro to XML DOM
Reading XML Data

3. What is the association between
Tech.Ed-India 2006 and Vineet Gupta?

Working with Nodes
xPath Expressions
Q&A

A) Track Owner

B) Speaker

C) Event Owner

D) Keynote Speaker

Contact ME
Intro to XML DOM

4. What is SOA?

Reading XML Data
Working with Nodes
xPath Expressions
Q&A
Contact ME

A) Service
Oriented
Architecture

B) Solutions
Oriented
Architecture

C) Security
Oriented
Architecture

D) Scalable
Operational
Architecture
Intro to XML DOM
Reading XML Data

How to Participate

Working with Nodes
xPath Expressions
Q&A
Contact ME

• Please send your responses
to response@erfolgcs.com
– Subject = “Microsoft Webcast
Contest – TechEd 2006 – Data
Platform and Architecture”
Intro to XML DOM
Reading XML Data
Working with Nodes
xPath Expressions
Q&A
Contact ME

© 2006 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
XPath
XPathXPath
XPath
 
Xpath
Xpath Xpath
Xpath
 
Querring xml with xpath
Querring xml with xpath Querring xml with xpath
Querring xml with xpath
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
XSLT and XPath - without the pain!
XSLT and XPath - without the pain!XSLT and XPath - without the pain!
XSLT and XPath - without the pain!
 
Xml query language and navigation
Xml query language and navigationXml query language and navigation
Xml query language and navigation
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
XQuery - a technical overview
XQuery -  a technical overviewXQuery -  a technical overview
XQuery - a technical overview
 
Sax parser
Sax parserSax parser
Sax parser
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
X path
X pathX path
X path
 
XML SAX PARSING
XML SAX PARSING XML SAX PARSING
XML SAX PARSING
 
Parsing XML Data
Parsing XML DataParsing XML Data
Parsing XML Data
 
Java and XML
Java and XMLJava and XML
Java and XML
 
Xpath
XpathXpath
Xpath
 
Sedna XML Database System: Internal Representation
Sedna XML Database System: Internal RepresentationSedna XML Database System: Internal Representation
Sedna XML Database System: Internal Representation
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
 
6 xml parsing
6   xml parsing6   xml parsing
6 xml parsing
 

Destacado (10)

Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
XSLT
XSLTXSLT
XSLT
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FO
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Xml dom
Xml domXml dom
Xml dom
 
XSLT
XSLTXSLT
XSLT
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 

Similar a XML and XPath details (20)

Introduce to XML
Introduce to XMLIntroduce to XML
Introduce to XML
 
Unit 2
Unit 2 Unit 2
Unit 2
 
XML
XMLXML
XML
 
25dom
25dom25dom
25dom
 
XML
XMLXML
XML
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 
Extbase object to xml mapping
Extbase object to xml mappingExtbase object to xml mapping
Extbase object to xml mapping
 
Unit iv xml dom
Unit iv xml domUnit iv xml dom
Unit iv xml dom
 
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
20120606 Lazy Programmers Write Self-Modifying Code /or/ Dealing with XML Ord...
 
XMl
XMlXMl
XMl
 
XML
XMLXML
XML
 
Harvester_presentaion
Harvester_presentaionHarvester_presentaion
Harvester_presentaion
 
Xml unit1
Xml unit1Xml unit1
Xml unit1
 
Xml
XmlXml
Xml
 
XML-Extensible Markup Language
XML-Extensible Markup Language XML-Extensible Markup Language
XML-Extensible Markup Language
 
Dos and donts
Dos and dontsDos and donts
Dos and donts
 
Approaches to document/report generation
Approaches to document/report generation Approaches to document/report generation
Approaches to document/report generation
 
Introductionto Xm Lmessaging
Introductionto Xm LmessagingIntroductionto Xm Lmessaging
Introductionto Xm Lmessaging
 
Dom
Dom Dom
Dom
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 

Más de DSK Chakravarthy (19)

Break the ICE with DSK
Break the ICE with DSKBreak the ICE with DSK
Break the ICE with DSK
 
Intelligent Machines for Industry 4.0
Intelligent Machines for Industry 4.0Intelligent Machines for Industry 4.0
Intelligent Machines for Industry 4.0
 
Initial Meetup of Hyderabad Chapter of BAI
Initial Meetup of Hyderabad Chapter of BAIInitial Meetup of Hyderabad Chapter of BAI
Initial Meetup of Hyderabad Chapter of BAI
 
ROC, not ROI
ROC, not ROIROC, not ROI
ROC, not ROI
 
Hacking the Quality
Hacking the QualityHacking the Quality
Hacking the Quality
 
agile 3.0
agile 3.0 agile 3.0
agile 3.0
 
Architectures
ArchitecturesArchitectures
Architectures
 
ROC for DevOPs
ROC for DevOPsROC for DevOPs
ROC for DevOPs
 
Cognitive agility
Cognitive agilityCognitive agility
Cognitive agility
 
Microsoft Products and Classification
Microsoft Products and ClassificationMicrosoft Products and Classification
Microsoft Products and Classification
 
What's new in Wcf4
What's new in Wcf4What's new in Wcf4
What's new in Wcf4
 
The Degree of Understanding
The Degree of UnderstandingThe Degree of Understanding
The Degree of Understanding
 
What's new in .NET Framework v4.5
What's new in .NET Framework v4.5What's new in .NET Framework v4.5
What's new in .NET Framework v4.5
 
Relat EVE estimates
Relat EVE estimatesRelat EVE estimates
Relat EVE estimates
 
Journey to Next level Agility
Journey to Next level AgilityJourney to Next level Agility
Journey to Next level Agility
 
It Market
It MarketIt Market
It Market
 
Intro Cloud Computing
Intro Cloud ComputingIntro Cloud Computing
Intro Cloud Computing
 
Designingapplswithnet
DesigningapplswithnetDesigningapplswithnet
Designingapplswithnet
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 

Último

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Último (20)

Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

XML and XPath details

  • 1. XML DOM Functionality in .NET DSK Chakravarthy http://dskc.blogspot.com dskcheck@msn.com http://msmvps.com/blogs/Chakravarthy
  • 2. Intro to XML DOM Reading XML Data Agenda Working with Nodes xPath Expressions Q&A Contact ME • You can see the agenda along the entire presentation • Q&A is at the End of session
  • 3. Intro to XML DOM Reading XML Data What I talk about Working with Nodes xPath Expressions Q&A Contact ME • The basics of reading and writing XML, programmatically • The important classes associated with XML documents in the System.XML namespace • How to Read XML Data • How to Traverse in XML DOM using xPath expressions
  • 4. Intro to XML DOM Are you ready ? Reading XML Data Working with Nodes xPath Expressions Q&A Contact ME Prerequisites •Basic Understanding of XML •Ability to read code
  • 5. Intro to XML DOM Reading XML Data Introduction to XML DOM Getting Started Working with Nodes xPath Expressions Q&A Contact ME • Many apps need to read/write XML data • Perhaps need to: – Store or retrieve configuration settings – Read/write data stored in XML format – Handle inter-application data transfer • XML programming required for all these • System.Xml.XmlDocument class provides support for handling XML
  • 6. Intro to XML DOM Reading XML Data Introduction to XML DOM What I’ll cover now Working with Nodes xPath Expressions Q&A Contact ME • NET Framework uses XML in many ways – Provides several techniques for working with XML • Only cover tree-based, in-memory handling • Other sessions cover other techniques, including the XmlReader/XmlWriter classes
  • 7. Intro to XML DOM Reading XML Data Introduction to XML DOM .NET APIs for working with XML Working with Nodes xPath Expressions Q&A Contact ME • Two main .NET APIs for working with XML: – Cached, read/write, random access • XML Document Object Model (DOM) • Tree-based, in-memory cache • Represented by the XmlDocument class – Non-cached, forward-only, read-only access • Represented by the XmlReader/XmlWriter classes
  • 8. Intro to XML DOM Reading XML Data Introduction to XML DOM Tree-Based XML Handling 1/4 Working with Nodes xPath Expressions Q&A Contact ME • Using this API, XML data loaded synchronously into a “tree” – Contains root node, and multiple child nodes – Each XML element corresponds to one or more nodes in the tree – Each node (except root node) has a parent node – Each node (except root node) can have multiple siblings – Each node can have multiple children
  • 9. Intro to XML DOM Reading XML Data Introduction to XML DOM Tree-Based XML Handling 2/4 Working with Nodes xPath Expressions Q&A Contact ME • Data loaded into memory – Provides random access to individual nodes – Can search for any node, at will • Tree-based structure represents XML infoset – This is the data stored in the serialized XML format – API doesn’t care about angle brackets and quotes • Just the data and its relationships
  • 10. Intro to XML DOM Reading XML Data Introduction to XML DOM Tree-Based XML Handling 3/4 Working with Nodes xPath Expressions Q&A Contact ME • Turns this XML content: <bookstore> <book genre="novel" publicationdate="1997" ISBN="1-861001-57-8"> <title>Pride And Prejudice</title> <author> <first-name>Jane</first-name> <last-name>Austen</last-name> </author> <price>24.95</price> </book> </bookstore>
  • 11. Intro to XML DOM Reading XML Data Introduction to XML DOM Tree-Based XML Handling Working with Nodes xPath Expressions Q&A • Into this data structure bookstore Contact ME book publication date publication date publication date title author firstname lastname price 4/4
  • 12. Intro to XML DOM Reading XML Data Introduction to XML DOM Non-Cached XML Handling Working with Nodes xPath Expressions Q&A Contact ME • Allows for fast access – No waiting for data to load • Requires less overhead • Doesn’t allow random access to data – Data flows to application in the order it appears within the original XML stream • Not covered here
  • 13. Intro to XML DOM Reading XML Data Introduction to XML DOM What is XML DOM? Working with Nodes xPath Expressions Q&A Contact ME • To provide standard mechanism for programmatically working with data – W3C proposed a standard API for working with XML – XML Document Object Model is the result • Provides software vendors with API for manipulating XML data • Before .NET, VB developers used MSXML COM component – Now use System.Xml namespace
  • 14. Demonstaration -- 0 investigating a sample file – Grocery store
  • 15. Intro to XML DOM Introduction to XML DOM Sample file as Datastructure Reading XML Data Working with Nodes Grocery Store xPath Expressions departments Q&A Contact ME department department Name = “Fruits” Name = “Breads” #text Brain’s Groceries Item Item Id=“B1” Store name Name Id=“F1” Name #text Wonder Bread Item Type = “Muffin” Id=“B2” Name #text Blueberry Muffin #text Apple Price Price Price #text 3.99 #text 1.29 New New #text 0.99
  • 16. Intro to XML DOM Reading XML Data Reading XML Data Load XML Data Working with Nodes xPath Expressions Q&A Contact ME • Need to load XML data into an XmlDocument object – Parse persisted XML into tree-based structure in memory • Create instance of XmlDocument object • Call Load method, providing file name – Other alternative means for loading, as well • Work with data in tree-based format • Retrieve OuterXml property to view XML
  • 17. Intro to XML DOM Reading XML Data Reading XML Data Working with Node’s children 1/2 Working with Nodes xPath Expressions Q&A Contact ME • Calling Load method fills data structure – Single root element, possibly other nodes • Sample root node contains three children – XML declaration (processing instruction) – Comment – GroceryStore document element • XmlDocument inherits from XmlNode class – Document == root node • Use HasChildNodes and ChildNodes
  • 18. Intro to XML DOM Reading XML Data Reading XML Data Working with Node’s children Working with Nodes xPath Expressions Q&A Contact ME • Interesting issues: – No recursion • Just displays information about the immediate children of selected node – Name properties differ • xml, #comment, #text, real names – Checking HasChildNodes is redundant • If your intent is to iterate through the nodes 2/2
  • 19. Demonstaration -- 1 Load XML Data Child Nodes Visit All Nodes Elements By Name Text Nodes
  • 20. Intro to XML DOM Reading XML Data Working with Nodes Retrieve nodes matching Criteria Working with Nodes xPath Expressions Q&A Contact ME • GetElementsByTagName works well, but limited • For more general criteria, use SelectNodes or SelectSingleNode methods of XmlNode • Can pass XPath query – XPath is powerful, and complex – Can only touch on it here
  • 21. Intro to XML DOM Reading XML Data Working with Nodes Getting started with xPath 1/2 Working with Nodes xPath Expressions Q&A Contact ME • xPath expressions "know" where to start looking, based on object whose method you call • Use "//" separator to indicate what follows is a descendant, at any level • Use "/" separator to indicate what follows is a direct descendant
  • 22. Intro to XML DOM Reading XML Data Working with Nodes Getting started with xPath 2/2 Working with Nodes xPath Expressions Q&A Contact ME • For example: – //Department//Name • Looks within Department node (at any lower level) for Name (at any level below Department) • Use "*" to look for any element name • To match root node of starting object, simply list the name
  • 23. Intro to XML DOM Reading XML Data Working with nodes More about XPATH 1/2 Working with Nodes xPath Expressions Q&A Contact ME • To match existence of a child node, – use: //Item[New]/Name • Looks for Item that contains a New element, then matches Name element of the Item • To match existence of an attribute, use: – //Item[@Type] • Looks for a Department node with a Name attribute
  • 24. Intro to XML DOM Reading XML Data Working with nodes More about XPATH 2/2 Working with Nodes xPath Expressions Q&A • To match specific values, use: – //Department[@Name= 'Fruits'] Contact ME • Once you have the XPath expression, and the retrieved node list, iterate through nodes
  • 25. Intro to XML DOM Reading XML Data Working with nodes Reference to specific Node Working with Nodes xPath Expressions Q&A Contact ME • Use XmlNode.SelectSingleNode method • Retrieves reference to first matching node • Best when: – You know there 's only one match – You actually want a relative (parent?) of the node you find
  • 26. Demonstaration -- 2 Select Nodes Select Single Node Find Relatives
  • 27. Intro to XML DOM Reading XML Data Working with nodes Retrieve Node attributes Working with Nodes xPath Expressions Q&A Contact ME • XmlNode.Attributes property retrieves XmlAttributeCollection object • Collection of XmlAttribute objects – Nodes with a name, and a value • If you just want a single attribute – Use GetNamedItem method of Attributes collection • Display all department names? – Name is an attribute of Department element
  • 28. Demonstaration -- 3 Retrieve Attributes Single Attribute
  • 29. Intro to XML DOM XmlDocument Conclusion Reading XML Data Working with Nodes xPath Expressions Q&A Contact ME • Derived from the XmlNode class • Represents an entire (in memory) XML document • Supports DOM Level 1 and Level 2 Core functionality • Reading & writing built on top of XmlReader & XmlWriter • Load a document and generate the DOM – Using: URI, file, XmlReader, XmlTextReader or Stream
  • 30. Intro to XML DOM Reading XML Data Summary Working with Nodes xPath Expressions Q&A Contact ME • In this session, we looked into: – How to load XML data into memory, using the XmlDocument class – How to read through XML data • retrieving elements by name • by using XPATH • by relative path – How to deal with node attributes
  • 31. Intro to XML DOM Reading XML Data Questions ? Working with Nodes xPath Expressions Q&A Contact ME • Request you to drop me a line • Doesn’t mean that you forget to post them at B.NET • You can expect reply from both mail & at the discussion thread
  • 32. Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q&A Contact ME The Webcast Quiz! • Four questions, multiple choice type – More than one maybe correct • Two lucky winners will win an Orchid Music Player • If you participate in the contest and are among the 2 lucky winners, your name will be featured on http://www.microsoft.com/india/web casts/
  • 33. Intro to XML DOM Reading XML Data Working with Nodes 1. What are the key themes in the Data Platform track at TechEd 2006 India? xPath Expressions Q&A Contact ME A) Programming, Database Management and BI B) Service Oriented Architecture and Robust Data Management C) Integrated D) Future of Solution Scenarios Computing and role of real-world Data Management Intelligence
  • 34. Intro to XML DOM Reading XML Data 2. Select 3 core themes under Data Management at Tech.Ed 2006 India. Working with Nodes xPath Expressions Q&A A) Security B) Monitoring and Analysis C) Scalability D) Robust integration of Development Tools and RDBMS Contact ME
  • 35. Intro to XML DOM Reading XML Data 3. What is the association between Tech.Ed-India 2006 and Vineet Gupta? Working with Nodes xPath Expressions Q&A A) Track Owner B) Speaker C) Event Owner D) Keynote Speaker Contact ME
  • 36. Intro to XML DOM 4. What is SOA? Reading XML Data Working with Nodes xPath Expressions Q&A Contact ME A) Service Oriented Architecture B) Solutions Oriented Architecture C) Security Oriented Architecture D) Scalable Operational Architecture
  • 37. Intro to XML DOM Reading XML Data How to Participate Working with Nodes xPath Expressions Q&A Contact ME • Please send your responses to response@erfolgcs.com – Subject = “Microsoft Webcast Contest – TechEd 2006 – Data Platform and Architecture”
  • 38. Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q&A Contact ME © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Notas del editor

  1. It is the Webcast Quiz time. I will ask you in the next couple of minutes, a set of four questions which will have multiple options. One or more options maybe correct for a question. What you have to do is to note down the answer to the question, and then send your answers to the email address we give later. Here goes.
  2. I hope every one had enough time to note the answers. You can send your answers to the email address above. But if you find these questions rather easy,