Home Mājas » » Dot Net Dot Net

XPath Tutorial with Examples XPath Tutorial ar piemēriem

This post is a small introduction for xpath (XML Path Language) is a terse (non-XML) syntax for addressing portions of an XML document. Šis amats ir neliels ievads par xpath (XML Path Language) ir kodolīgs (ne-XML) sintakse, lai risinātu porcijas XML dokumentu. XPath has rapidly been adopted by developers as a small query language. XPath ir strauji pieņēma izstrādātājiem par mazu vaicājumu valodu.

With the increase in usage of xml being sent on internet for transferring data there was huge need of some standard way for accessing data in a simple and fast manner.Thats what is Xpath is about. Ar pieaugums izmantošanu xml sūta par interneta datu nosūtīšanai bija milzīga vajadzība dažus standarta veids, kā piekļūt datiem, ir vienkāršs un ātri manner.Thats to, kas ir Xpath ir aptuveni.

Introduction to Xpath Ievads Xpath

XPath is a language for finding information in an XML document. XPath ir valoda, lai atrastu informāciju par XML dokumentu. It allows consumers of Xml to query it and access any part of it directly.It may return null, a string, a number or an xml node itself. Tas ļauj patērētājiem XML meklēt un piekļūt tā daļā directly.It var atgriezties null, a string, vairākas vai XML mezglu pati. XPath is used to navigate through elements and attributes in an XML document. XPath tiek izmantota, lai virzītos caur elementi un atribūti ir XML dokuments.

What is XPath? Kas ir XPath?

  • XPath is a syntax for defining parts of an XML document. XPath ir sintakse, lai noteiktu daļu XML dokumentu.
  • XPath uses path expressions to navigate in XML documents . XPath izmanto ceļa apzīmējumiem, lai virzītos XML dokumentiem.
  • XPath contains a library of standard functions. XPath ir bibliotēka, standarta funkcijas.
  • XPath is a major element in XSLT. XPath ir svarīga XSLT.
  • XPath is a W3C Standard. XPath ir W3C standarts.

Now when it says expression we are not talking abt scary regular expressions but simple expressions which we use it for our desktop searching often like [.*].Now lets start with an example and go ahead in this. Tagad, kad tā saka, vārda mēs neesam runāju Abt biedējošu regulārus izteicienus, bet vienkāršs izteicieniem, kas mums to izmantot mūsu darbvirsmas meklēšana bieži tāpat [.*]. Tagad ļauj sākt ar piemēru un doties uz priekšu šajā.

Example XML File. Piemērs XML datni.

<?xml version=”1.0″ encoding=”ISO-8859-1″?> <? xml version = "1.0" encoding = "ISO-8859-1"?>

<bookstore>[document node]< <bookstore> [dokuments mezglā] <

book><title lang=”en”>[attribute]Harry Potter</title>[element]< book> <title lang="en"> [atribūta] Harry Potter </ title> [elements] <

author>JKRowling</author> autors> JKRowling </ author>

<year>2005</year> <year> 2005 </ gads>

<price>29.99</price> <price> 29,99 </ cenas>

</book> </ book>

</bookstore> </ grāmatu>

An XML is treated as a tree of nodes.If we closely look there are around seven kind of nodes defined by XPath.The root of this tree is called as document node or root node.The nodes are element, attribute, text, namespace, processing-instruction, comment, and document (root)nodes. XML tiek uzskatīts par koku nodes.If mēs cieši skatīties ir aptuveni septiņi veida mezglu noteikts XPath.The root šo koku sauc par dokumentu mezglā vai root node.The mezgli ir elements, atribūts, tekstu namespace, pārstrādes, piemēram, komentārus, un dokuments (root) punktu.

XML NODES XML mezglu

  1. bookstore is root node,title is an element and lang='en' is attribute. grāmatu ir root mezglā, virsraksts ir elements, un lang = "en" ir atribūta.
  2. ParentEach element and attribute has one parent.In the example; the book element is the parent of the title, author, year, and price. ParentEach elementu un atribūtu ir viens parent.In piemērs; grāmatu elements ir mātes nosaukumu, autoru, gadu, un cenu.
  3. Children:Element nodes may have zero, one or more children.In the example; the title, author, year, and price elements are all children of the book element. Bērni: Element mezgliem var būt nulle, viens vai vairāki children.In piemērs; nosaukumu, autoru, gadu, un cenu elementiem ir visu bērnu grāmatu elementu.
  4. Siblings : Nodes that have the same parent.In the example; the title, author, year, and price elements are all siblings. Vecvecākus: mezgliem, kuriem ir tāds pats parent.In piemērs; nosaukumu, autoru, gadu, un cenu elementiem ir visas vecvecākus.
  5. Ancestors : A node's parent, parent's parent, etc.In the example; the ancestors of the title element are the book element and the bookstore element. Senči: A mezglā mātes, mātes mātes, etc.In piemērs, un senči no title elements ir grāmata elements un grāmatu elementu.
  6. Descendants: A node's children, children's children, etc. In the example; descendants of the bookstore element are the book, title, author, year, and price elements. Pēctečiem: A mezglā bērniem, bērnu bērniem utt piemērs; pēcteči no grāmatu elements ir grāmata, nosaukums, autors, gads, un cenu elementus.

Now since we are clear with the basics of xpath we can take an example of it and work along.Let's try to learn some basic XPath syntax by looking at some examples. Tagad, kopš mēs ir skaidrs ar pamati xpath mēs varam veikt, piemēram, to un darba along.Let 's mēģinātu mācīties dažus pamata XPath sintakse, aplūkojot dažus piemērus.

The XML Example Document XML piemērs dokuments

 <?xml version="1.0" encoding="ISO-8859-1"?> <? xml version = "1.0" encoding = "ISO-8859-1"?> 
 <bookstore> <bookstore> 
 <book category="COOKING"> <book category="COOKING"> 
 <title lang="en">Everyday Italian</title> <title lang="en"> Ikdienas itāliešu </ title> 
 <author>Giada De Laurentiis</author> <author> Giada De Laurentiis </ author> 
 <year>2005</year> <year> 2005 </ gads> 
 <price>30.00</price> <price> 30,00 </ cenas> 
 </book> </ book> 
 <book category="CHILDREN"> <book category="CHILDREN"> 
 <title lang="en">Harry Potter</title> <title lang="en"> Harry Potter </ title> 
 <author>J K. Rowling</author> <author> J K. Rowling </ author> 
 <year>2005</year> <year> 2005 </ gads> 
 <price>29.99</price> <price> 29,99 </ cenas> 
 </book> </ book> 
 <book category="WEB"> <book category="WEB"> 
 <title lang="en">XQuery Kick Start</title> <title lang="en"> XQuery Kick Sākums </ title> 
 <author>James McGovern</author> <author> James McGovern </ author> 
 <author>Per Bothner</author> <author> Per Bothner </ author> 
 <author>Kurt Cagle</author> <author> Kurt Cagle </ author> 
 <author>James Linn</author> <author> James Linn </ author> 
 <author>Vaidyanathan Nagarajan</author> <author> Vaidyanathan Nagarajan </ author> 
 <year>2003</year> <year> 2003 </ gads> 
 <price>49.99</price> <price> 49,99 </ cenas> 
 </book> </ book> 
 <book category="WEB"> <book category="WEB"> 
 <title lang="en">Learning XML</title> <title lang="en"> Learning XML </ title> 
 <author>Erik T. Ray</author> <author> Erik T. Ray </ author> 
 <year>2003</year> <year> 2003 </ gads> 
 <price>39.95</price> <price> 39,95 </ cenas> 
 </book> </ book> 
 </bookstore> </ grāmatu> 

Selecting Nodes: Izvēloties mezglu:


We will use the Microsoft XMLDOM object to load the XML document and the selectNodes() function to select nodes from the XML document: Mēs izmantosim Microsoft XMLDOM priekšmets ielādēt XML dokumentu un selectNodes () funkciju, lai izvēlētos mezglu no XML document:

set xmlDoc=CreateObject(”Microsoft.XMLDOM”) noteikt xmlDoc = CreateObject ( "Microsoft.XMLDOM")
xmlDoc.async=”false” xmlDoc.async = "nepatiess"
xmlDoc.load(”books.xml”)xmlDoc.selectNodes(path expression) xmlDoc.load ( "books.xml") xmlDoc.selectNodes (ceļa apzīmējums)

Select all book Nodes: Izvēlēties visus grāmatu mezglu:
The following example selects all the book nodes under the bookstore element: Ar šādu piemēru izvēlas visu grāmatu mezglu ar grāmatu elements:

xmlDoc.selectNodes(”/bookstore/book”) xmlDoc.selectNodes ( "/ grāmatu / Grāmata"),

Select the First book Node: Izvēlieties pirmo grāmatu mezglu:

The following example selects only the first book node under the bookstore element: Ar šādu piemēru izvēlas tikai pirmais grāmatu mezglā saskaņā ar grāmatu elements:

xmlDoc.selectNodes(”/bookstore/book[0]“) xmlDoc.selectNodes ( "/ grāmatu / grāmatu [0]")

Select the prices: Izvēlieties cenas:

The following example selects the text from all the price nodes: Ar šādu piemēru izvēlas tekstu no visas cenu mezglu:

xmlDoc.selectNodes(”/bookstore/book/price/text()”) xmlDoc.selectNodes ( "/ grāmatu / grāmata / cena / text ()")

Selecting price Nodes with Price>35: Izvēloties cenu mezglu ar cenu> 35:

The following example selects all the price nodes with a price higher than 35: Ar šādu piemēru izvēlas visu cenu mezglu ar cenu, kas ir augstāka nekā 35:

xmlDoc.selectNodes(”/bookstore/book[price>35]/price”) xmlDoc.selectNodes ( "/ grāmatu / book [cenas> 35] / cena")

Thus from the above example we can see how to navigate through an xml document and navigate through it and retrieve the data.This was just a small idea how it works.XPath is bigger than this.If you have still some query i would refer to go through more books to see the actual implementation of it in detail. Tādējādi no iepriekš Piemēram, mēs varam redzēt, kā, lai virzītos caur XML dokumentu un virzītos caur to un paņemt to data.This bija tikai neliela ideja, kā tā works.XPath ir lielāks nekā this.If jums ir vēl query i norāda uz iet caur vairāk grāmatas redzēt faktisko īstenošanu no tās detaļām.

For a Complete details i would like to recommend to go through standards and follow the links Ir pilnīga informācija Vēlos ieteikt iet ar standartiem un sekojiet saites

External links: Ārējās saites:

Tagged with: Tagged with:

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/NorwegianÖversätta till Svensk/Swedishहिन्दी अनुवाद करने के लिए/Hindi
Tradueix al català/CatalanTulkot uz latviešu/LatvianPreložiť do slovenčiny/SlovakVertaal aan het Nederlands/Dutchترجمة الى العربية/ArabicTraduzca al Español/SpanishTraduisez au Français/French
Traduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplified中文翻译/Chinese TraditionalПереклад на українську/Ukrainian

SMS abonētPrint This Post

Posted on 1st January 2008 by Posted par 1 janvāris 2008 by Ashish Mohta Ashish Mohta , A tech blogger who writes about solving day to day problems of people who use computer. , A tech blogger, kas raksta par risināšana ikdienas problēmas, kas saistītas ar cilvēkiem, kuri lieto datoru. He also writes on How to use the applications like Office, PC tips, Online tools,Browsers and more. All posts by Viņš arī raksta par to, kā izmantot lietojumiem, piemēram, Office, PC padomus, Online instrumentus, pārlūkprogrammas un vairāk. Visi amatu ar Ashish Mohta Ashish Mohta | Connect with me @ | Savienoties ar mani @ Twitter Čivināt | | Linkedin Linkedin | | Facebook Facebook | | Stumble Paklupt | Need more help? | Vajadzīga palīdzība? Ask your Questions at our Jautājiet pēc mūsu Support Center Support Center

Leave your response! Atstājiet savu reakciju!

Be nice. Be nice. Keep it clean. Paturiet to tīram. Stay on topic. Palieciet uz tēmu. No spam. Nr surogātpastu.

You can use these tags: Jūs varat izmantot šos tagus:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>