XML DOM Functionality in.NET DSK Chakravarthy 94496 12273

Slides:



Advertisements
Similar presentations
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Advertisements

XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
UFCEKG-20-2 Data, Schemas & Applications Lecture 5 XML & PHP.
An Introduction to XML Based on the W3C XML Recommendations.
DBLABNational Taiwan Ocean University1/35 A Document-based Approach to Indexing XML Data Ya-Hui Chang and Tsan-Lung Hsieh Department of Computer Science.
XPath Eugenia Fernandez IUPUI. XML Path Language (XPath) a data model for representing an XML document as an abstract node tree a mechanism for addressing.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
XSL Transformations Lecture 8, 07/08/02. Templates The whole element is a template The match pattern determines where this template applies Result element(s)
1 Extensible Markup Language: XML HTML: widely supported protocol for formatting data XML: widely supported protocol for describing data XML is quickly.
XML Primer. 2 History: SGML vs. HTML vs. XML SGML (1960) XML(1996) HTML(1990) XHTML(2000)
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
SD2520 Databases using XML and JQuery
.NET and XML (or XML in.NET) David Oguns Matt Harding.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
XML Fundementals XML vs.. HTML XML vs.. HTML XML Document (elements vs. attributes) XML Document (elements vs. attributes) XML and RDBMS XML and RDBMS.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
Presentation XML. NET SEMINAR By: Siddhant Ahuja (SID)
XPath XPath is used to navigate through elements and attributes in an XML document. XPath is a major element in W3C's XSLT standard - and XQuery and XPointer.
ASP.NET and XML Presented By: Shravan S. Mylavarapu 1.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
1 XPath XPath became a W3C Recommendation 16. November 1999 XPath is a language for finding information in an XML document XPath is used to navigate through.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
LINQ TO XML Mike Taulty Developer & Platform Group Microsoft UK
Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 4 - XML.
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
The XML Document Object Model (DOM) Aug’10 – Dec ’10.
Querying Structured Text in an XML Database By Xuemei Luo.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
WORKING WITH XML IN THE.NET FRAMEWORK. Accessing an XML File Basic activities: open it, read it.NET Framework provides structured and unstructured mechanisms.
DAT 379 XML Today And Tomorrow Mark Fussell Lead Program Manager Microsoft Corporation.
Database Systems Part VII: XML Querying Software School of Hunan University
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
Declaratively Producing Data Mash-ups Sudarshan Murthy 1, David Maier 2 1 Applied Research, Wipro Technologies 2 Department of Computer Science, Portland.
DOM Programming The Document Object Model standardises  what an application can see of the XML data  how it can access it An XML structure is a tree.
WPI, MOHAMED ELTABAKH PROCESSING AND QUERYING XML 1.
XML Refresher Course Bálint Joó School of Physics University of Edinburgh May 02, 2003.
XML – Its Role and Use Ben Forta Senior Product Evangelist, Macromedia.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
CS 157B: Database Management Systems II February 13 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
.NET and XML (or XML in.NET) Matt Harding David Oguns.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
1 XPath. 2 Agenda XPath Introduction XPath Nodes XPath Syntax XPath Operators XPath Q&A.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
XML DOM Week 11 Web site:
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
XML for .NET Session 1 Introduction to XML Introduction to XSLT
In this session, you will learn to:
Displaying XML Data with XSLT
Introduction to the Document Object Model
Week 11 Web site: XML DOM Week 11 Web site:
Processing XML.
More Sample XML By Sadia Anjum.
New Perspectives on XML
Presentation transcript:

XML DOM Functionality in.NET DSK Chakravarthy

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Agenda You can see the agenda along the entire presentation Q&A is at the End of session

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME What I talk about 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 Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Are you ready ? Prerequisites Basic Understanding of XML Ability to read code

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Getting Started 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 Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM What I’ll cover now 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 Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM.NET APIs for working with XML 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 Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Tree-Based XML Handling 1/4 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 Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Tree-Based XML Handling 2/4 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 Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Tree-Based XML Handling 3/4 Turns this XML content:Turns this XML content: <book genre="novel" publicationdate="1997" ISBN=" "> Pride And Prejudice Jane Austen 24.95

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Tree-Based XML Handling 4/4 Into this data structureInto this data structure bookstore book publication date title author price firstname lastname

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Non-Cached XML Handling 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 Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM What is XML DOM? 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 Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Introduction to XML DOM Sample file as Datastructure Grocery Store Name = “Breads” Store name #text Brain’s Groceries department Name = “Fruits” department departments Item Id=“B1” Name #text Wonder Bread Price #text 1.29 New Item Id=“B2” Name #text Blueberry Muffin Price #text 3.99 New Type = “Muffin” Item Id=“F1” Name #text Apple Price #text 0.99

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Reading XML Data Load XML Data 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 Working with Nodes xPath Expressions Q & A Contact ME Reading XML Data Working with Node’s children 1/2 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 Working with Nodes xPath Expressions Q & A Contact ME Reading XML Data Working with Node’s children 2/2 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

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 xPath Expressions Q & A Contact ME Working with Nodes Retrieve nodes matching Criteria 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 xPath Expressions Q & A Contact ME Working with Nodes Getting started with xPath 1/2 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 xPath Expressions Q & A Contact ME Working with Nodes Getting started with xPath 2/2 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 xPath Expressions Q & A Contact ME Working with nodes More about XPATH 1/2 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: Looks for a Department node with a Name attribute

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Working with nodes More about XPATH 2/2 To match specific values, use: 'Fruits'] Once you have the XPath expression, and the retrieved node list, iterate through nodes

Intro to XML DOM Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME Working with nodes Reference to specific Node 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 xPath Expressions Q & A Contact ME Working with nodes Retrieve Node attributes 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 Reading XML Data Working with Nodes xPath Expressions Q & A Contact ME XmlDocument Conclusion 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 Working with Nodes xPath Expressions Q & A Contact ME Summary 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 Working with Nodes xPath Expressions Q & A Contact ME Questions ? 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