Ana içeriğe geç

ExportToXml

Veri tablosu içeriğini XML verilerine aktarır. Veri tablosundaki her satır için belirtilen XPath konumunda yeni bir XML alt öğesi oluşturulur.

1
$Database.ExportToXml(query: QueryWithMappings):DataTable

Parametreler

QueryWithMappings sorgusu
    Dışa aktarılacak verileri tanımlayan bir sorgu.

Döndürür

Dışa aktarılan verileri içeren bir DataTable iş akışı örneği.

Notlar

Bu IncludeAllColumns parametre belirtilmediğinde varsayılan davranış, sorgunun yalnızca açıkça belirtilen sütunları döndürmesidir. Hiçbir sütun belirtilmezse sorgu, tablodaki tanımlı tüm sütunları döndürür.

XML veri modelinizin ve SQL tablo sütunlarınızın tasarımı, kullanım kolaylığı açısından önemlidir. XML düğümü ve tablo sütunu adları aynı olduğunda bu yöntem bunları otomatik olarak eşler.

Info

Bu $Database.ExportToXml ve $Database.ImportFromXml yöntemler, veritabanı tablosunda ve veri modelinde benzersiz bir birincil anahtar alanı gerektirir.

Eşleme işlevi Bir eşleme işlevi, değerleri kaydetmeden önce dönüştürmek için kullanılabilir; örneğin, veritabanına kaydetmeden önce parolayı şifrelemek için. Daha fazla bilgi için bkz. $Database.ImportFromXml .

Örnek

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$Database.ExportToXml({
    TargetSchema : 'MySchema',
    TargetTable : 'Accounts',
    XPath : 'Accounts/Account',
    // map values whose names are not identical to SQL column names
    Map : function (accountXml) {
        accountXml.SetValue('Password', this.Password);
        accountXml.SetValue('Type/Code', this.AccountType);
    }
});

Veritabanı içeriğini XML'e aktarma

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// For following xml structure
// <Root>
//    <Groups></Groups>
// </Root>
$Database.ExportToXml({
    Parameters : {
        TargetSchema : 'HR',
        TargetTable : 'Groups'
    },
    XPath : 'Groups/Group',
    Order : [
        {Name : 'Name', Type : 'Ascending'}
    ]
});
// Xml updated as;
// <Root>
//   <Groups>
//     <Group>
//        <Name>Developers (Junior)</Name>
//     </Group>
//     <Group>
//        <Name>Testers</Name>
//     </Group>
//   </Groups>
// </Root>

Alt sorgularla dışa aktarma

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// Export corporations with the subcorporations
$Database.ExportToXml({
    Parameters : {
        TargetSchema : 'Evrak',
        TargetTable : 'Kurum'
    },
    XPath : 'Corporations/Corporation',
    SubQueries : [
        {Name : 'SubCorporations'}
    ]
});

Info

İki SQL tablonuz olduğunu varsayalım: Corporations ve SubCorporations; ayrıca Corporations tablosundan SubCorporations tablosuna, adı da SubCorporationsolan bire-çok ilişkisi bulunuyor. Bu ilişkinin güncelleme kuralını şu şekilde ayarlamayı da unutmayın: Cascade.

Tablo sütunlarını XML alanlarıyla aynı adlara sahip olacak şekilde tanımladıktan sonra bu kod, her şirketi SQL tablosundan XML alanlarına aktarmanızı sağlar. Ayrıca ilişkili SubCorporations öğelerini SubCorporations XML düğümlerine aktarır ve aşağıdaki XML verilerini oluşturur.

Dışa aktarılan XML verileri

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<GeneralDefinitions>
  <Corporations>
     <Corporation>
        <Id>9b7383a3-67ae-4fed-a135-1f981b165c43</Id>
        <Name>Corporation A</Name>
        <ShortName>CorpA</ShortName>
        <SubCorporations>
           <SubCorporation>
              <Id>309069b4-4274-4063-b7ad-75c5657d7474</Id>
              <Name>SubCorporation A 1</Name>
              <ShortName>SubCorpA1</ShortName>
           </SubCorporation>
           <SubCorporation>
              <Id>6ba3cc79-9ff7-4232-8f61-9245a38fd2bb</Id>
              <Name>SubCorporation A 2</Name>
              <ShortName>SubCorpA2</ShortName>
           </SubCorporation>
        </SubCorporations>
     </Corporation>
     <Corporation>
        <Id>5a900112-a869-41cf-931c-7379c1df518e</Id>
        <Name>Corporation B</Name>
        <ShortName>CorpB</ShortName>
        <SubCorporations>
           <SubCorporation>
              <Id>8e7ca6d2-5629-4f87-82ed-73c72cfb171e</Id>
              <Name>SubCorporation B 1</Name>
              <ShortName>SubCorpB1</ShortName>
           </SubCorporation>
           <SubCorporation>
              <Id>7c5f330e-68d8-45f0-800e-04e2f7e035e0</Id>
              <Name>SubCorporation B 2</Name>
              <ShortName>SubCorpB2</ShortName>
           </SubCorporation>
        </SubCorporations>
     </Corporation>
  </Corporations>
</GeneralDefinitions>

İç içe alt sorgularla dışa aktarma

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$Database.ExportToXml({
    Parameters : {
        TargetSchema : 'Contract',
        TargetTable : 'Events'
    },
    Where : {
        Criteria : [
            {Name : 'ReminderDate', Value : $Calendar.Today, Comparison : 'LessThan'},
            {Name : 'Durum', Value : 'IPT', Comparison : 'Different'},
            {Name : 'Type', Value : 'R'},
            {Name : 'Status', Value : 'W'}
        ]
    },
    SubQueries : [
        {
            Name : 'Contract',
            Parameters : {
                IncludeAllColumns : 'True'
            },
            SubQueries : [
                {
                    Name : 'Party'
                },
                {
                    Name : 'Versions'
                },
                {
                    Name : 'Events'
                }
            ]
        }
    ],
    XPath : 'ContractEvent',
    Order : [
        {Name : 'ReminderDate', Type : 'Descending'}
    ]
});

XML eşlemeleriyle dışa aktarma

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$Database.ExportToXml({
    Parameters : {
        TargetSchema : 'HR',
        TargetTable : 'OrganizationUnitPositionMembers',
        IncludeAllColumns : 'True'
    },
    Columns : [
        {
            Name : 'Employee',
            Properties : {
                XPath : 'Id'
            }
        },
        {
            Name : 'Employee.Person.DisplayName',
            Properties : {
                XPath : 'Name'
            }
        },
        {
            Name : 'OrganizationUnitPosition.Organization',
            Properties : {
                XPath : 'Department'
            }
        },
        {
            Name : 'OrganizationUnitPosition.Organization.Name',
            Properties : {
                XPath : 'Department/@Name'
            }
        }
    ],
    Where : {
        Criteria : [
            {
                Name : 'OrganizationUnitPosition.Manager',
                Value : 'D7B70176-C44D-44BB-A8C0-7900BC5DAF2A',
                Condition : 'And'
            },
            {Name : 'Employee.User.Disabled', Value : true, Comparison : 'Different', Condition : 'And'}
        ]
    },
    XPath : 'EmployeeList/Employee'
});

Ayrıca bkz.