Aracılığıyla paylaş


XPath sorguları (SQLxml 4.0) eksenler belirtme

Eksenleri XPath sorguları nasıl belirtilen aşağıdaki örneklerde gösterilmiştir.

XPath sorguları Bu örneklerde SampleSchema1.xml içinde yer alan eşleme şema karşı belirtilir.Bu örnek şeması hakkında daha fazla bilgi için bkz: Örnek XPath örnekleri (SQLxml 4.0) xsd şema açıklamalı.

Örnekler

A.İçerik düðümünün alt öğelerini almak

Aşağıdaki XPath sorgusu tümünü seçer <kişi> içerik düðümünün alt öğeler:

/child::Person

Sorgu child olan eksen ve Contact düğüm sınama (true if Person olan bir <öğesi> düğüm, çünkü <öğesi> birincil düğüm türü ile ilişkili child eksen).

The child axis is the default.Bu nedenle, sorgu olarak yazılabilir.

/Person

XPath sorgusu eşleme şema karşı sınamak için

  1. Copy örnek şema kodu ve bir metin dosyasına yapıştırın.Dosyayı SampleSchema1.xml kaydedin.

  2. Aşağıdaki şablon (XPathAxesSampleA.xml) oluşturun ve SampleSchema1.xml kaydedildiği dizine kaydedin.

    <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <sql:xpath-query mapping-schema="SampleSchema1.xml">
        /Person
      </sql:xpath-query>
    </ROOT>
    

    Dizin yol (SampleSchema1.xml) eşleme şema şablonun kaydedileceği dizini ile ilişkili olduğu için belirtilen.Mutlak bir yol da, örneğin belirtilebilir:

    mapping-schema="C:\MyDir\SampleSchema1.xml"
    
  3. Oluşturun ve sqlxml 4.0 sınama komut dosyası (Sqlxml4test.vbs) şablonu yürütmek için kullanın.

    Daha fazla bilgi için bkz: ado SQLxml yürütme kullanarak 4.0 sorgular.

Şablon yürütme kısmi bir sonuç küme aşağıdadır:

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">

<Person BusinessEntityID="1" LastName="Achong" FirstName="Gustavo" Title="Mr." />

<Person BusinessEntityID="2" LastName="Abel" FirstName="Catherine" Title="Ms." />

<Person BusinessEntityID="3" LastName="Abercrombie" FirstName="Kim" Title="Ms." />

<Person BusinessEntityID="4" LastName="Acevedo" FirstName="Humberto" Title="Sr." />

...

</ROOT>

B.İçerik düðümünün grandchildren almak

Aşağıdaki XPath sorgusu tümünü seçer <Sipariş> , alt öğesi <Müşteri> içerik düðümünün alt öğesi:

/child::Customer/child::Order

Sorgu child olan eksen ve Customer ve Order düğüm sınamaları (müşteri ve sipariş ise bu düğüm sınamaları doğruysa <öğesi> düğümleri, çünkü <öğesi> olduğu için birincil düğüm düğüm child eksen).Her düğümü eşleştirmek için <Müşteri>, eşleşen düğümler <siparişleri> eklenen sonucu.Sadece <Sipariş> döndürülen sonuç küme.

The child axis is the default.Bu nedenle, sorgu olarak belirtilebilir:

/Customer/Order

XPath sorgusu eşleme şema karşı sınamak için

  1. Copy örnek şema kodu ve bir metin dosyasına yapıştırın.Dosyayı SampleSchema1.xml kaydedin.

  2. Aşağıdaki şablon (XPathAxesSampleB.xml) oluşturun ve dizine kaydedin nereye:

    <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <sql:xpath-query mapping-schema="SampleSchema1.xml">
        /Customer/Order
      </sql:xpath-query>
    </ROOT>
    

    Dizin yol (SampleSchema1.xml) eşleme şema şablonun kaydedileceği dizini ile ilişkili olduğu için belirtilen.Mutlak bir yol da, örneğin belirtilebilir:

    mapping-schema="C:\MyDir\SampleSchema1.xml"
    
  3. Oluşturun ve sqlxml 4.0 sınama komut dosyası (Sqlxml4test.vbs) şablonu yürütmek için kullanın.

    Daha fazla bilgi için bkz: ado SQLxml yürütme kullanarak 4.0 sorgular.

Şablon yürütme kısmi bir sonuç küme aşağıdadır:

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">

<Order SalesOrderID="Ord-43860" SalesPersonID="280"

OrderDate="2005-08-01T00:00:00"

DueDate="2005-08-13T00:00:00"

ShipDate="2005-08-08T00:00:00">

<OrderDetail ProductID="Prod-729" UnitPrice="226.8571"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-732" UnitPrice="440.1742"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-738" UnitPrice="220.2496"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-753" UnitPrice="2576.3544"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-756" UnitPrice="1049.7528"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-758" UnitPrice="1049.7528"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-761" UnitPrice="503.3507"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-762" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-763" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-765" UnitPrice="503.3507"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-768" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-770" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

</Order>

...

</ROOT>

XPath sorgusu olarak belirtilirse, Customer/Order/OrderDetail, her düğüm eşleşen gelen <Müşteri> sorgu gider, <Sipariş> öğeleri.Ve her düğümü eşleştirmek için <Sipariş>, sorgu düğümleri ekler <OrderDetail> sonucu.Sadece <OrderDetail> döndürülen sonuç küme.

C.Use ..to specify the parent axis

Tüm aşağıdaki sorgu alır <Sipariş> bir üst öğeleriyle <Müşteri> öğe ile bir CustomerID öznitelik değeri 1.Sorguyu kullanır child üst bulmak için yüklemi eksen <Sipariş> öğesi.

/child::Customer/child::Order[../@CustomerID="1"]

The child axis is the default axis.Bu nedenle, sorgu olarak belirtilebilir:

/Customer/Order[../@CustomerID="1"]

XPath sorgusu eşdeğerdir:

/Customer[@CustomerID="1"]/Order.

Not

XPath sorgusu /Order[../@CustomerID="1"] bir hata döndürecektir çünkü hiçbir üst <Sipariş>.Olabilir, ancak eşleme şema içeren öğeleri <Sipariş>, XPath değil başlamak istediğini; at Sonuç olarak, <Sipariş> olarak kabul edilir olmasına en üst düzey öğe türü belge.

XPath sorgusu eşleme şema karşı sınamak için

  1. Copy örnek şema kodu ve bir metin dosyasına yapıştırın.Dosyayı SampleSchema1.xml kaydedin.

  2. Aşağıdaki şablon (XPathAxesSampleC.xml) oluşturun ve dizine kaydedin nereye:

    <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <sql:xpath-query mapping-schema="SampleSchema1.xml">
        /Customer/Order[../@CustomerID="1"]
      </sql:xpath-query>
    </ROOT>
    

    Dizin yol (SampleSchema1.xml) eşleme şema şablonun kaydedileceği dizini ile ilişkili olduğu için belirtilen.Mutlak bir yol da, örneğin belirtilebilir:

    mapping-schema="C:\MyDir\SampleSchema1.xml"
    
  3. Oluşturun ve sqlxml 4.0 sınama komut dosyası (Sqlxml4test.vbs) şablonu yürütmek için kullanın.

    Daha fazla bilgi için bkz: ado SQLxml yürütme kullanarak 4.0 sorgular.

Şablon yürütme kısmi bir sonuç küme aşağıdadır:

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">

<Order SalesOrderID="Ord-43860" SalesPersonID="280"

OrderDate="2005-08-01T00:00:00"

DueDate="2005-08-13T00:00:00"

ShipDate="2005-08-08T00:00:00">

<OrderDetail ProductID="Prod-729" UnitPrice="226.8571"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-732" UnitPrice="440.1742"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-738" UnitPrice="220.2496"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-753" UnitPrice="2576.3544"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-756" UnitPrice="1049.7528"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-758" UnitPrice="1049.7528"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-761" UnitPrice="503.3507"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-762" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-763" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-765" UnitPrice="503.3507"

OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-768" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-770" UnitPrice="503.3507"

OrderQty="1" UnitPriceDiscount="0" />

</Order>

...

</Order>

</ROOT>

D.Öznitelik belirtineksen

Aşağıdaki XPath sorgusu tümünü seçer <Müşteri> ile içerik düðümünün alt öğeleri bir CustomerID öznitelik değeri 1:

/child::Customer[attribute::CustomerID="1"]

İfadede attribute::CustomerID, attribute olan eksen ve CustomerID düğüm sınama (, CustomerID düðüm sýnamasý true olan bir öznitelik, çünkü <özniteliği> olduğu için birincil düğüm düğüm attribute eksen).

Kısayol attribute eksen (@) belirtilebilir ve çünkü child varsayılan ekseni sorgudan atlanabilir:

/Customer[@CustomerID="1"]

XPath sorgusu eşleme şema karşı sınamak için

  1. Copy örnek şema kodu ve bir metin dosyasına yapıştırın.Dosyayı SampleSchema1.xml kaydedin.

  2. Aşağıdaki şablon (XPathAxesSampleD.xml) oluşturun ve SampleSchema1.xml kaydedildiği dizine kaydedin.

    <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">
      <sql:xpath-query mapping-schema="SampleSchema1.xml">
        child::Customer[attribute::CustomerID="1"]
      </sql:xpath-query>
    </ROOT>
    

    Dizin yol (SampleSchema1.xml) eşleme şema şablonun kaydedileceği dizini ile ilişkili olduğu için belirtilen.Mutlak bir yol da, örneğin belirtilebilir:

    mapping-schema="C:\MyDir\SampleSchema1.xml"
    
  3. Oluşturun ve sqlxml 4.0 sınama komut dosyası (Sqlxml4test.vbs) şablonu yürütmek için kullanın.

    Daha fazla bilgi için bkz: ado SQLxml yürütme kullanarak 4.0 sorgular.

Şablon yürütme kısmi bir sonuç küme aşağıdadır:

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">

<Customer CustomerID="1" SalesPersonID="280"

TerritoryID="1" AccountNumber="1"

CustomerType="S" Orders="Ord-43860 Ord-44501 Ord-45283 Ord-46042">

<Order SalesOrderID="Ord-43860" SalesPersonID="280"

OrderDate="2005-08-01T00:00:00"

DueDate="2005-08-13T00:00:00"

ShipDate="2005-08-08T00:00:00">

<OrderDetail ProductID="Prod-729" UnitPrice="226.8571"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-732" UnitPrice="440.1742"

OrderQty="1" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-738" UnitPrice="220.2496"

OrderQty="1" UnitPriceDiscount="0" />

...

</Order>

...

</Customer>

</ROOT>