ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: Xquery :: XQuery ½éÉÜ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

Xquery
XQuery ½éÉÜ
XQuery ʵÀý
XQuery FLWOR ±í´..
XQuery FLWOR + H..
XQuery ÊõÓï
XQuery Óï·¨
XQuery Ìí¼ÓÔªËØº..
XQuery Ñ¡ÔñºÍ¹ýÂ..
XQuery º¯Êý
XQuery ÕªÒª
XQuery ²Î¿¼

XQuery ½éÉÜ


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-22 ä¯ÀÀ:3453 :: ::

The best way to explain XQuery is to say that XQuery is to XML what SQL is to database tables.
¶ÔXQuery×îºÃµÄ½âÊÍÊÇ£ºXQueryÏ൱ÓÚXMLµÄ²éѯÓï¾ä£»XQueryÓëXMLÖ®¼äµÄ¹ØÏµ£¬¾ÍÈçͬSQLÓï¾äºÍÊý¾Ý¿â±í¡£

XQuery is designed to query XML data - not just XML files, but anything that can appear as XML, including databases.
XQueryÓÃÓÚ²éѯXMLÊý¾Ý —— ²»½ö½öÊÇXMLÎļþ£¬»¹°üÀ¨Ò»ÇÐÒÔXMLÐÎʽ³öÏֵĶ«Î÷£¬°üÀ¨Êý¾Ý¿â¡£


What You Should Already Know
ÄãÓ¦¸ÃÒѾ­¾ß±¸µÄ֪ʶ

Before you continue you should have a basic understanding of the following:
ÔÚ¼ÌÐøÏÂÃæµÄѧϰ֮ǰ£¬ÄãÊ×ÏÈÓ¦¸Ã»ù±¾ÕÆÎÕÏÂÊö֪ʶ£º

  • HTML / XHTML
  • XML / XML ÃüÃû¿Õ¼ä
  • XPath

If you want to study these subjects first, find the tutorials on our Home page.
Èç¹ûÄãÏ£ÍûÏÈѧϰÉÏÊö֪ʶ£¬Çë¿´ÎÒÃǵĽ̳ÌÖ÷Ò³¡£


What is XQuery?
ʲôÊÇXQuery£¿

  • XQuery is the language for querying XML data
    XQueryÊDzéѯXMLÊý¾ÝµÄÓïÑÔ
  • XQuery for XML is like SQL for databases
    XQueryÓëXMLµÄ¹ØÏµÀàËÆÓÚSQLÓëÊý¾Ý¿âµÄ¹ØÏµ
  • XQuery is built on XPath expressions
    XQuery Êǽ¨Á¢ÔÚXPath±í´ïʽ»ù´¡ÉϵÄ
  • XQuery is defined by the W3C
    XQueryÊÇÓÉW3C ¶¨ÒåµÄ
  • XQuery is supported by all the major database engines (IBM, Oracle, Microsoft, etc.)
    ËùÓÐÖØÒªµÄÊý¾Ý¿âÒýÇæ£¨È磺IBM¡¢Oracle¡¢Microsoft£¬µÈµÈ£©¶¼Ö§³ÖXQuery
  • XQuery will become a W3C standard - and developers can be sure that the code will work among different products
    XQuery½«»á³ÉΪW3CµÄ±ê×¼ —— ¿ª·¢Õß¶¼È·ÐÅ´úÂë¿ÉÒÔÔÚ²»Í¬µÄ²úÆ·Ö®¼äÔËÐÐ

XQuery is About Querying XML
XQuery ÊÇÓÃÓÚ²éѯXMLµÄ

XQuery is a language for finding and extracting elements and attributes from XML documents.
XQueryÊÇÓÃÓÚ´ÓXMLÎĵµÖвéÕÒºÍÌáÈ¡ÔªËØºÍÊôÐÔµÄÓïÑÔ¡£

Here is an example of a question that XQuery could solve:
ÏÂÃæÊÇÒ»¸ö¹ØÓÚXQueryËùÄܽâ¾öµÄÎÊÌâµÄ°¸Àý£º

"Select all CD records with a price less than $10 from the CD collection stored in the XML document called cd_catalog.xml".
´Ó´æ´¢ÔÚÃûΪ “cd_catalog.xml” µÄXMLÎĵµÄÚµÄCD¼¯ÖÐÑ¡ÔñËùÓм۸ñµÍÓÚ10ÃÀÔªµÄCD³ªÆ¬¡£


XQuery and XPath
XQuery ºÍ XPath

XQuery 1.0 and XPath 2.0 share the same data model and support the same functions and operators. If you have already studied XPath you will have no problems with understanding XQuery.
XQuery 1.0 ºÍ XPath 2.0 ¾ßÓÐÏàͬµÄÊý¾ÝÄ£ÐͲ¢Ö§³ÖÏàͬµÄº¯ÊýºÍ²Ù×÷·û¡£Èç¹ûÄãÒѾ­ÕÆÎÕÁËXPathµÄÏà¹ØÖªÊ¶£¬ÄÇô£¬Àí½âXQuery¾Í²»³ÉÎÊÌâÁË¡£

You can read more about XPath in our XPath Tutorial.
Äã¿ÉÒÔ ÔÚÎÒÃǵÄXPath ½Ì³ÌÖÐѧϰ¸ü¶à¹ØÓÚXPathµÄ֪ʶ¡£


XQuery - Examples of Use
XQuery —— ʹÓð¸Àý

XQuery can be used to:
XQuery ¿ÉÓÃÓÚÏÂÊö²Ù×÷£º

  • Extract information to use in a Web Service
    »ñÈ¡ÔÚWeb·þÎñÖÐʹÓõÄÐÅÏ¢
  • Generate summary reports
    ²úÉú×ۺϱ¨¸æ¡£
  • Transform XML data to XHTML
    °ÑXMLÊý¾Ýת»»³ÉXHTMLÐÎʽ
  • Search Web documents for relevant information
    ÔÚWebÎĵµÖÐËÑË÷Ïà¹ØÐÅÏ¢

XQuery is Not (Yet) a Web Standard
XQuery ²¢²»ÊÇÍøÂç±ê×¼

XQuery is compatible with several W3C standards, such as XML, Namespaces, XSLT, XPath, and XML Schema.
XQueryºÍһЩW3CµÄ±ê×¼ÊÇÏ໥ÎǺϵģ¬ÀýÈ磺XML¡¢Namespaces [ÃüÃû¿Õ¼ä]¡¢XSLT¡¢XPath ºÍ XML Schema¡£

However, XQuery 1.0 is not yet a W3C Recommendation (XQuery is a Working Draft). Hopefully it will be a recommendation in the near future.
È»¶ø£¬XQuery 1.0 ²¢²»ÊÇW3CµÄÍÆ¼ö±ê×¼£¨XQuery ½öÊÇÒ»·Ý¹¤×÷²Ý°¸£©¡£ÏàÐÅÔÚ²»¾ÃµÄ½«À´£¬Ëü»á±ä³É W3C ÍÆ¼öµÄ±ê×¼°É¡£

ÆÀÂÛ (0) All