Aracılığıyla paylaş


XPath sorguları (SQLxml 4.0) Boole değerli yüklemler belirtme

Aşağıdaki örnekler nasıl Boole değerli yüklemler XPath sorguları belirtilir.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.Birden çok yüklemler belirtin

Aşağıdaki XPath sorgusu birden çok yüklemler verilen Sipariş No ve müşteri kimliği için sipariş bilgileri bulmak için kullanır:

/child::Customer[attribute::CustomerID="1"]/child::Order[attribute::OrderID="Ord-43860"]

Kısayol attribute eksen (@) belirtilebilir ve çünkü child eksen varsayılan değerdir, sorgudan atlanabilir:

/Customer[@CustomerID="1"]/Order[@SalesOrderID="Ord-43860"]

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 (BooleanValuedPredicatesA.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">
        /Customer[@CustomerID="1"]/Order[@SalesOrderID="Ord-43860"]
      </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.

    İşte sonuç:

<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>

B.Birbirini izleyen ve iç içe yüklemler belirtin

Aşağıdaki sorgu yüklemler birbirini izleyen kullanarak gösterir.Tüm sorgu döndürür <Müşteri> hem de içerik düðümünün alt öğeleri bir SalesPersonID öznitelik değeri 277 ve bir TerritoryID öznitelik değeri 3:

/child::Customer[attribute::SalesPersonID="277"][attribute::TerritoryID="3"]

The query returns the <Customer> elements that satisfy both the conditions specified in the predicates.

Kısayol attribute eksen (@) belirtilebilir ve çünkü child eksen varsayılan değerdir, sorgudan atlanabilir:

/Customer[@SalesPersonID="277"][@TerritoryID="3"]

Aşağıdaki XPath sorgusu iç içe yüklemler kullanımını göstermektedir.Tüm sorgu döndürür <Müşteri> içeren içerik düðümünün alt öğeler <Sipariş> ile en az bir alt öğe <Sipariş> öğesi olan bir SalesPersonID öznitelik değeri 2.

/Customer[Order[@SalesPersonID=2]]

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 (nestedSuccessive.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">
             /Customer[@SalesPersonID="277"][@TerritoryID="3"]
      </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.

Kısmi bir sonuç şudur:

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

<Customer CustomerID="22" SalesPersonID="277" TerritoryID="3"

AccountNumber="22" CustomerType="S"

Orders="Ord-43874 Ord-44519 Ord-46989 Ord-48013 Ord-49130 Ord-50274 Ord-51807 Ord-57113 Ord-63162 Ord-69495">

<Order SalesOrderID="Ord-43874" SalesPersonID="277"

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

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

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

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

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

</Order>

...

</Customer>

<Customer CustomerID="39" SalesPersonID="277" TerritoryID="3"

AccountNumber="39" CustomerType="S"

Orders="Ord-47428 Ord-48367 Ord-49529 Ord-50742 Ord-53591 Ord-59051 Ord-65301 Ord-71912"> <Order SalesOrderID="Ord-47428" SalesPersonID="277"

OrderDate="2006-09-01T00:00:00"

DueDate="2006-09-13T00:00:00"

ShipDate="2006-09-08T00:00:00">

<OrderDetail ProductID="Prod-759" UnitPrice="563.7528" OrderQty="2" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-769" UnitPrice="563.7528" OrderQty="1" UnitPriceDiscount="0" />

...

</Order>

...

</Customer>

...

</ROOT>

C.Üst düzey bir doðrulamayý belirtmek

Aşağıdaki sorgu döndürür <Müşteri> olan içerik düðümünün alt öğe düğümleri <Sipariş> öğesi alt öğeleri.Sorgu sınamaları konumu yol üst düzey yüklemi olarak:

/child::Customer[child::Order]

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 (TopLevelPredicate.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">
        /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.

Kısmi sonuç 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>

<Order SalesOrderID="Ord-44501" SalesPersonID="280" OrderDate="2005-11-01T00:00:00" DueDate="2005-11-13T00:00:00" ShipDate="2005-11-08T00:00:00">

<OrderDetail ProductID="Prod-725" UnitPrice="226.8571" OrderQty="3" UnitPriceDiscount="0" />

<OrderDetail ProductID="Prod-726" UnitPrice="226.8571" OrderQty="2" UnitPriceDiscount="0" />

...

</Order> ...

</Customer>

...

</ROOT>