top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

    Get Free Article Updates

Facebook Login
Site Registration
Print Preview

Benefits of XPath

0 votes
14 views

Benefits of XPath

XPath is designed for XML documents. It provides a single syntax that you can use for queries, addressing, and patterns. XPath is concise, simple, and powerful.

XPath has many benefits:

  • Syntax is simple for the simple and common cases.
  • Any path that can occur in an XML document and any set of conditions for the nodes in the path can be specified.
  • Any node in an XML document can be uniquely identified.

XPath is designed to be used in many contexts. It is applicable to providing links to nodes, for searching repositories, and for many other applications.

XML Document in XPath

In XPath, an XML document a viewed conceptually as a tree in which each part of the document is represented as a node as shown in figure below:

XPath has seven types of nodes. They are:

  • Root: The XPath tree has a single root node, which contains all other nodes in the tree.
  • Element: Every element in a document has a corresponding element node that appears in the tree under the root node. Within an element node appear all of the other types of nodes that corresponding to the element’s content. Element nodes may have a unique identifier associated with them that is used to reference the node with XPath.
  • Attribute: Each element node has an associated set of attribute nodes, the element is the parent of each of these attribute nodes, however, an attribute node is not a child of its parent element.
  • Text: Character data is grouped into text nodes. Characters inside comments, processing instructions and attribute values do not produce text nodes. The text node has a parent node and it may the child node too.
  • Comment: There is a comment node for every comment, except for any comment that occurs within the documents type declaration. The comment node has a parent node and it may be the child node too.
  • Processing instruction: There is a processing instruction node for every processing instruction, except for any processing instruction that occurs within the document type declaration. The processing instruction node has a parent node and it may be the child node too.
  • Namespace: Each element has an associated set of namespace nodes. Although the namespace node has a parent node, the namespace node is not considered a child of its parent node because they are not contained in a parent node, but are used to provide descriptive information about their parent node.
posted Dec 2 by Frank Lee 1 abuse reported

  Promote This Article
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button


Related Articles

XPath Expressions

XPath Expressions are statements that can extract useful information from the XPath tree. Instead of just finding nodes, one can count them, add up numeric values, compare strings, and more. They are much like statements in a functional programming language. Every XPath expression evaluates to a single value.

There are four types of expressions in XPath. They are:

  • Node-set: A node-set is an unordered group of nodes from the input document that match an expression’s criteria.
  • Boolean: A Boolean has one of two values: true of false. XSLT allows any kind of data to be transformed into a Boolean. This is often done implicity when a string or a number or a node-set used where a Boolean is expected.
  • Number: XPath numbers are numeric values useful for counting nodes and performing simple arithmetic. The numbers such as 43 or -7000 that look like integers are stored as doubles. Non-number values, such as strings and Booleans, are converted to numbers automatically as necessary.
  • String: A string is a sequence of zero or more Unicode characters. Other data types can be converted to strings using the string() function.

XPath Funcitons

XPath defines various functions required for XPath 2.0, XQuery 1.0 and XSLT 2.0. The different functions and Accessor, AnyURI, Node, Error and Trace, Sequence, Context, Boolean, Duration/Date/Time, String, QName and Numeric.

XML Path Language (XPath) functions can be used to refine XPath queries and enhance the programming power and flexibility of XPath. Each function in the function library is specified using a function prototype that provides the return type, function name, and argument type. If an argument type is followed by a question mark, the argument is optional; otherwise, the argument is required. Function names are case-sensitive.

The default prefix for the function namespace is fn.

READ MORE

Introduction to XPath

XPath can be thought of as a query language such as SQL. However, rather than extracting information from a database, it extracts information from an XML document. XPath is a language for retrieving from a database, it extracts information from an XML document. XPath is a language for retrieving information from a XML document. XPath is used to navigate through elements and attributes in an XML document. Thus, XPath allows identifying parts of an XML document.

XPath provides a common syntax as shown in figure:-

 

  • XSLT: XSLT is a language for transforming XML documents into XML, HTML, or text.
  • XQuery: XQuery builds on XPath and is a language for extracting from XML documents.

Benefits of XPath

XPath is desingned for XML documents. It provides a single syntax that you can use for queries, addressing, and patterns. XPath is concise, simple, and powerful.

XPath has many benefits:

  • Syntax is simple for the simple and common cases
  • Any path that can occur in an XML document and any set of conditions for the nodes in the path can be specified.
  • Any node in an XML document can be uniquely identified

XPath is designed to be used in many contexts. It is applicable to providing links to nodes, for searching repositories, and for many other applications.

READ MORE

Style Sheets

Need of Style Sheets

Style sheets are a set of rules that describe the appearance of data in an XML document.

XML was inspired by the problems posed by presentational markup. Presentational markup does not describe data, it defines the appearance of data. In a document, if you had to change all proper nouns from bold to italics, you would have to do it manually for each proper noun. Presentation markup failed to provide same look and feel across multiple devices such as computers, Personal Digital Assistant (PDA) devices, and cell phones.

Style sheets and XML solve these problems. XML describes data. Style sheets define the appearance of data. However, both XML and style sheets are defined in separate files.

 

Fig: Formatting Document with Style Sheet.

Various Style Sheets

There are several style sheets available. However, following two are the most popular style sheets:

  • Cascading Style Sheets (CSS): CSS allows you to control the appearance of data in HTML and XML  documents by providing various properties to define:

     1. Position and size of data to be displayed

      2. Foreground and background color of data

      3. Font to be used to display data

      4. Spacing between data

  • Extensible Style Sheet (XSL): XSL is a style sheet language used to define the appearance of data contained only in XML documents. However, it also allows you to transform XML documents.
READ MORE

Evolution of XML

In order to address the issues raised by earlier markup languages, the Extensible Markup Language (XML) was created XML is a W3C recommendation.

XML is a set of rules for defining semantic tags that break a document into parts and identify the different parts of the document. XML was developed over HTML because of the basic differences between them.

                           HTML

                           XML

HTML was designed to display data.

XML was designed to carry data.

HTML displays data and focuses on how data looks.

XML describes data and focuses on what data is.

HTML displays information.

XML describes information.

                                  FIG: Difference between HTML and XML

An XML code:

<?xml version=”1.0” encoding=”iso-8859-1”?>

<watch>

    <name>Titan</name>

    <price>$50</price>

    <description> A bright brown fox jumps over the lazy dog</description>

</watch>

                                  

Features of XML

Features of XML are as follows:

  • XML stands for Extensible Markup Language

  • XML is a markup language much like HTML

  • XML was designed to describe data

  • XML tags are not predefined. You must define your own tags

  • XML uses a DTD or an XML Schema to describe the data

  • XML with a DTD or XML Schema is designed to be self-descriptive

XML Markup

XML markup defines the physical and logical layout of the document. XML can be considered as an information container. It contains shapes labels. Structures and also protects information. XML employs a tree-based structure to represent a document. The basic foundation of XML is laid down by symbols embedded in the text known as markup. The markup combines the text and extra information about the text such as its structure and presentation. The markup divides the information into a hierarchy of character data and container-like elements and its attributes. A number of software programs process electronic documents use a markup.

XML’s markup divides a document into separate information containers calld elements. A document consists of one outermost element called root element that contains all the other elements. Plus some optional administrative information at the top. Known as XML declaration. Following code demonstrates the elements.

Code Snippet:

<?xml version=”1.0” encoding=”iso-8859-1” ?>

<FlowerPlanet>

      <Name>Rose</Name>

      <Price>$1</Price>

      <Description>Red in color</Description>

      <Number>700</Number>

</FlowerPlanet>

Where,

<Name>, <Price>, <Description> and <Number> inside the tags are elements.

<FlowerPlanet> and </FlowerPlanet> are the root elements.

The usage of XML can be observed in many real-life scenarios. It can be used in the fields of information sharing, single application usage, content delivery, re-use of data, separation of data and presentation, semantics, and so forth. News agencies are a common place where XML is used. News producers and news consumers often use a standard specification name XMLNews to produce, retrieve, and relay information across different systems in the world.

Note: XML is a subset of SGML, with the same goals, but with as much of the complexity eliminated as possible. This means that any document which follows XML’s syntax rules will also follow SGML’s syntax rules, and can therefore be read by existing SGML tools.

READ MORE
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...