schematron, multiple elements values compare - schematron

In schematron I have 2 files. In source01.xml there is a keyvalue (xacml-context:AttributeValue), with this keyvalue I want get the minimum value of servicelevel in source02.xml by comparing the value of the keyvalue with the value of "eh:ServiceProviderID" in source02.xml.
In de following example I want get "2" as result.
source01.xml
<xacml-context:Resource>
<xacml-context:Attribute AttributeId="urn:etoegang:core:ServiceID" DataType="http://www.w3.org/2001/XMLSchema#string">
<xacml-context:AttributeValue>01002</xacml-context:AttributeValue>
</xacml-context:Attribute>
<xacml-context:Attribute AttributeId="urn:etoegang:core:ServiceUUID" DataType="http://www.w3.org/2001/XMLSchema#string">
<xacml-context:AttributeValue>
</xacml-context:AttributeValue>
source02.xml
<eh:ServiceProvider>
<eh:ServiceProviderID>01001</eh:ServiceProviderID>
<eh:OrganizationDisplayName>company A</eh:OrganizationDisplayName>
<eh:Service>
<eh:ServiceID>DV:01506</eh:ServiceID>
<eh:ServiceLevel>1</eh:ServiceID>
...
</eh:Service>
<eh:Service>
<eh:ServiceID>DV:02506</eh:ServiceID>
<eh:ServiceLevel>2</eh:ServiceID>
...
</eh:Service>
<eh:Service>
<eh:ServiceID>DV:03506</eh:ServiceID>
<eh:ServiceLevel>3</eh:ServiceID>
...
</eh:Service>
</eh:ServiceProvider>
<eh:ServiceProvider>
<eh:ServiceProviderID>01002</eh:ServiceProviderID>
<eh:OrganizationDisplayName>company B</eh:OrganizationDisplayName>
<eh:Service>
<eh:ServiceID>DV:01507</eh:ServiceID>
<eh:ServiceLevel>2</eh:ServiceID>
...
</eh:Service>
<eh:Service>
<eh:ServiceID>DV:02507</eh:ServiceID>
<eh:ServiceLevel>2+</eh:ServiceID>
...
</eh:Service>
<eh:Service>
<eh:ServiceID>DV:03507</eh:ServiceID>
<eh:ServiceLevel>3</eh:ServiceID>
...
</eh:Service>
</eh:ServiceProvider>
<eh:ServiceProvider>
<eh:ServiceProviderID>01003</eh:ServiceProviderID>
<eh:OrganizationDisplayName>company C</eh:OrganizationDisplayName>
<eh:Service>
<eh:ServiceID>DV:02508</eh:ServiceID>
<eh:ServiceLevel>1</eh:ServiceID>
...
</eh:Service>
<eh:Service>
<eh:ServiceID>DV:03508</eh:ServiceID>
<eh:ServiceLevel>3</eh:ServiceID>
...
</eh:Service>
</eh:ServiceProvider>
schematron
<rule context="xacml-c:Attribute[#AttributeId='urn:etoegang:core:ServiceID']">
<let name="ServiceIdValue" value="xacml-c:AttributeValue"/>
<assert test="$ServiceIdValue=' '">ServiceID (<value-of select="$ServiceIdValue"/>) is the keyvalue.</assert>
<let name="DCValue" value="document('source02.xml')//*[name()='eh:ServiceProviderID']"/>
<assert test="$DCValue=' '">DCValue (<value-of select="$DCValue"/>) is the source02 value. </assert>
</rule>

Related

Check if the field contains certain values

I have documents who contains a lot of values, as:
"mydata":["699 50000 50002 50031",
"699 878",
"200000 200150 200170 200171",
"200000 200150 200170 200172",
"200000 200150 200170 200175",
"200000 200150 200170 200176",
"200000 200150 200170 200174",
"200000 200150 200170 200173",
"200000 200150 200170 200177",
"200000 200150 200190 200191",
"200000 200150 200190 200181"],
And I want to select the documents according to two select cases:
1/ The mydata field contains values between 200000 to 299999
I bring my documents with the
mydata:[200000 TO 299999]
clause. no problems.
2/ The mydata field contains values 1 to 199999
but if I do:
mydata:[1 TO 199999]
I bring back 0 documents, yet the mydata contains the values 699 50000 50002 50031 699 878 who are ok, so this document should be return.
How can I do that ? Thanks for help

SQL Query XML with 'where' clause

I am trying to retrieve a single row of data based on an XML attribute.
The SQL I have so far is:
select C.query('.')
from Bookmarks
cross apply XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
The data returned from this query is (4 rows of data)
<Bookmark Report="DataExplorer" Name="DataExplorer" CustomColumn1="Analysis" CustomColumn2="Data Explorer" Description="Benefit Plan Count" SaveTime="2020-02-21T10:44:36-05:00" BookmarkID="79638e95-c5b7-43f1-b180-f5f31b50dea4" ExtraFile="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="People.ContactInfo.EmergencyContactList" Name="" CustomColumn1="Report" CustomColumn2="Emergency Contact List" Description="Engineering Emergency Contacts" SaveTime="2020-02-21T11:48:28-05:00" BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="22" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="1" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" />
<SessionParameters />
</Bookmark>
<Bookmark Report="TotalRewards.Compensation.SalaryAnalysis" Name="" CustomColumn1="Analysis" CustomColumn2="Salary Analysis" Description="Annual Pay by Employee" SaveTime="2020-02-21T12:03:02-05:00" BookmarkID="30da52af-55d3-4c06-985a-12d428731773" ExtraFile="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="Payroll.PayrollProcessing.PayrollAnalysis" Name="" CustomColumn1="Report" CustomColumn2="Payroll Analysis" Description="Payroll Age 40-49" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397" SaveTime="2020-02-21T12:50:26-05:00" BookmarkID="2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe" ExtraFile="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" rdAgLoadSaved="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml" />
<SessionParameters />
</Bookmark>
but this returns each Bookmark element (4 total). I would like to add a where clause to only return one Bookmark node based on the BookmarkID, but can't seem to figure out how to do this. Is there a way to add something like
where C.query('#BookmarkID') = '953e67ef-d45e-4fac-8d71-b2153a726612'
so that only one Bookmark node is returned?
You could use the value() method to get a single value:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
WHERE c.value('#BookmarkID', 'VARCHAR(36)') = '953e67ef-d45e-4fac-8d71-b2153a726612'
You can also filter directly in the nodes() method:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark[#BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612"]') as T(C);

read Xml into ms sql

I want to read the xml pasted below into sql. I tried several ways from the web to parse this xml without success.
I tried the following script:
CREATE TABLE [dbo].[Ejemplo2](
[RutEmisor][nvarchar](12) null,
[RutEnvia][nvarchar](12) null,
[RutReceptor][nvarchar](12) null,
[FchResol][nvarchar](12) null,
[NroResol][nvarchar](12) null
)
GO
DECLARE #messagebody XML
SELECT #messagebody = BulkColumn
FROM OPENROWSET(BULK 'C:\Ejemplo.xml', SINGLE_CLOB) AS X
INSERT INTO [dbo].[Ejemplo2]
select a.value(N'(./RutEmisor)[1]', N'nvarchar(12)') as [RutEmisor],
a.value(N'(./RutEnvia)[1]', N'nvarchar(12)') as [RutEnvia],
a.value(N'(./RutReceptor)[1]', N'nvarchar(12)') as [RutReceptor],
a.value(N'(./FchResol)[1]', N'nvarchar(12)') as [FchResol],
a.value(N'(./NroResol)[1]', N'nvarchar(12)') as [NroResol]
from #messagebody.nodes('/EnvioDTE/SetDTE/Caratula') as r(a);
Select * from dbo.Ejemplo2
But I get 0 rows
I tried with more simple examples and always return the data, but in this case I can't figure whats is wrong.
Any help on this will be appreciated.
The xml follows
<?xml version="1.0" encoding="ISO-8859-1"?>
<EnvioDTE xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd" version="1.0">
<SetDTE ID="SetDoc">
<TmstFirmaEnv>2003-10-13T09:33:22</TmstFirmaEnv>
<Caratula version="1.0">
<RutEmisor>97975000-5</RutEmisor>
<RutEnvia>7880442-4</RutEnvia>
<RutReceptor>60803000-K</RutReceptor>
<FchResol>2003-09-02</FchResol>
<NroResol>0</NroResol>
<SubTotDTE>
<TpoDTE>33</TpoDTE>
<NroDTE>1</NroDTE>
</SubTotDTE>
</Caratula>
<DTE version="1.0">
<Documento ID="F60T33">
<Encabezado>
<IdDoc>
<TipoDTE>33</TipoDTE>
<Folio>60</Folio>
<FchEmis>2003-10-13</FchEmis>
</IdDoc>
<Emisor>
<RUTEmisor>97975000-5</RUTEmisor>
<RznSoc>RUT DE PRUEBA</RznSoc>
<GiroEmis>Insumos de Computacion</GiroEmis>
<Acteco>31341</Acteco>
<CdgSIISucur>1234</CdgSIISucur>
<DirOrigen>Teatinos 120, Piso 4</DirOrigen>
<CmnaOrigen>Santiago</CmnaOrigen>
<CiudadOrigen>Santiago</CiudadOrigen>
</Emisor>
<Receptor>
<RUTRecep>77777777-7</RUTRecep>
<RznSocRecep>EMPRESA LTDA</RznSocRecep>
<GiroRecep>COMPUTACION</GiroRecep>
<DirRecep>SAN DIEGO 2222</DirRecep>
<CmnaRecep>LA FLORIDA</CmnaRecep>
<CiudadRecep>SANTIAGO</CiudadRecep>
</Receptor>
<Totales>
<MntNeto>100000</MntNeto>
<TasaIVA>19</TasaIVA>
<IVA>19000</IVA>
<MntTotal>119000</MntTotal>
</Totales>
</Encabezado>
<Detalle>
<NroLinDet>1</NroLinDet>
<CdgItem>
<TpoCodigo>INT1</TpoCodigo>
<VlrCodigo>011</VlrCodigo>
</CdgItem>
<NmbItem>Parlantes Multimedia 180W.</NmbItem>
<DscItem/>
<QtyItem>20</QtyItem>
<PrcItem>4500</PrcItem>
<MontoItem>90000</MontoItem>
</Detalle>
<Detalle>
<NroLinDet>2</NroLinDet>
<CdgItem>
<TpoCodigo>INT1</TpoCodigo>
<VlrCodigo>0231</VlrCodigo>
</CdgItem>
<NmbItem>Mouse Inalambrico PS/2</NmbItem>
<DscItem/>
<QtyItem>1</QtyItem>
<PrcItem>5000</PrcItem>
<MontoItem>5000</MontoItem>
</Detalle>
<Detalle>
<NroLinDet>3</NroLinDet>
<CdgItem>
<TpoCodigo>INT1</TpoCodigo>
<VlrCodigo>1515</VlrCodigo>
</CdgItem>
<NmbItem>Caja de Diskettes 10 Unidades</NmbItem>
<DscItem/>
<QtyItem>5</QtyItem>
<PrcItem>1000</PrcItem>
<MontoItem>5000</MontoItem>
</Detalle>
<TED version="1.0">
<DD>
<RE>97975000-5</RE>
<TD>33</TD>
<F>60</F>
<FE>2003-10-13</FE>
<RR>77777777-7</RR>
<RSR>EMPRESA LTDA</RSR>
<MNT>119000</MNT>
<IT1>Parlantes Multimedia 180W.</IT1>
<CAF version="1.0">
<DA>
<RE>97975000-5</RE>
<RS>RUT DE PRUEBA</RS>
<TD>33</TD>
<RNG>
<D>1</D>
<H>200</H>
</RNG>
<FA>2003-09-04</FA>
<RSAPK>
<M>0a4O6Kbx8Qj3K4iWSP4w7KneZYeJ+g/prihYtIEolKt3cykSxl1zO8vSXu397QhTmsX7SBEudTUx++2zDXBhZw==</M>
<E>Aw==</E>
</RSAPK>
<IDK>100</IDK>
</DA>
<FRMA algoritmo="SHA1withRSA">g1AQX0sy8NJugX52k2hTJEZAE9Cuul6pqYBdFxj1N17umW7zG/hAavCALKByHzdYAfZ3LhGTXCai5zNxOo4lDQ==</FRMA>
</CAF>
<TSTED>2003-10-13T09:33:20</TSTED>
</DD>
<FRMT algoritmo="SHA1withRSA">GbmDcS9e/jVC2LsLIe1iRV12Bf6lxsILtbQiCkh6mbjckFCJ7fj/kakFTS06Jo8i
S4HXvJj3oYZuey53Krniew==</FRMT>
</TED>
<TmstFirma>2003-10-13T09:33:20</TmstFirma>
</Documento>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#F60T33">
<Transforms>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>hlmQtu/AyjUjTDhM3852wvRCr8w=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>JG1Ig0pvSIH85kIKGRZUjkyX6CNaY08Y94j4UegTgDe8+wl61GzqjdR1rfOK9BGn93AMOo6aiAgolW0k/XklNVtM/ZzpNNS3d/fYVa1q509mAMSXbelxSM3bjoa7H6Wzd/mV1PpQ8zK5gw7mgMMP4IKxH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lo5nFACrPAeTtONbHa
ReyzeMDv2EganNEDJc9c+UNfAgMBAAGjggGYMIIBlDAjBgNVHREEHDAaoBgGCCsG
AQQBwQEBoAwWCjA3ODgwNDQyLTQwCQYDVR0TBAIwADA8BgNVHR8ENTAzMDGgL6At
hitodHRwOi8vY3JsLmUtY2VydGNoaWxlLmNsL2UtY2VydGNoaWxlY2EuY3JsMCMG
A1UdEgQcMBqgGAYIKwYBBAHBAQKgDBYKOTY5MjgxODAtNTAfBgNVHSMEGDAWgBTg
KP3S4GBPs0brGsz1CJEHcjodCDCB0AYDVR0gBIHIMIHFMIHCBggrBgEEAcNSBTCB
tTAvBggrBgEFBQcCARYjaHR0cDovL3d3dy5lLWNlcnRjaGlsZS5jbC8yMDAwL0NQ
Uy8wgYEGCCsGAQUFBwICMHUac0VsIHRpdHVsYXIgaGEgc2lkbyB2YWxpZG8gZW4g
Zm9ybWEgcHJlc2VuY2lhbCwgcXVlZGFuZG8gZWwgQ2VydGlmaWNhZG8gcGFyYSB1
c28gdHJpYnV0YXJpbywgcGFnb3MsIGNvbWVyY2lvIHkgb3Ryb3MwCwYDVR0PBAQD
AgTwMA0GCSqGSIb3DQEBBQUAA4GBABMfCyJF0mNXcov8iEWvjGFyyPTsXwvsYbbk
OJ41wjaGOFMCInb4WY0ngM8BsDV22bGMs8oLyX7rVy16bGA8Z7WDUtYhoOM7mqXw
/Hrpqjh3JgAf8zqdzBdH/q6mAbdvq/yb04JHKWPC7fMFuBoeyVWAnhmuMZfReWQi
MUEHGGIW</X509Certificate>
</X509Data>
</KeyInfo>
</Signature></DTE>
</SetDTE><Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#SetDoc">
<Transforms>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>4OTWXyRl5fw3htjTyZXQtYEsC3E=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>sBnr8Yq14vVAcrN/pKLD/BrqUFczKMW3y1t3JOrdsxhhq6IxvS13SgyMXbIN/T9ciRaFgNabs3pi732XhcpeiSmD1ktzbRctEbSIszYkFJY49k0eB+TVzq3eVaQr4INrymfuOnWj78BZcwKuXvDy4iAcx6/TBbAAkPFwMP9ql2s=</SignatureValue>
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>
tNEknkb1kHiD1OOAWlLKkcH/UP5UGa6V6MYso++JB+vYMg2OXFROAF7G8BNFFPQx
iuS/7y1azZljN2xq+bW3bAou1bW2ij7fxSXWTJYFZMAyndbLyGHM1e3nVmwpgEpx
BHhZzPvwLb55st1wceuKjs2Ontb13J33sUb7bbJMWh0=
</Modulus>
<Exponent>
AQAB
</Exponent>
</RSAKeyValue>
</KeyValue>
<X509Data>
<X509Certificate>MIIEgjCCA+ugAwIBAgIEAQAApzANBgkqhkiG9w0BAQUFADCBtTELMAkGA1UEBhMC
Q0wxHTAbBgNVBAgUFFJlZ2lvbiBNZXRyb3BvbGl0YW5hMREwDwYDVQQHFAhTYW50
aWFnbzEUMBIGA1UEChQLRS1DRVJUQ0hJTEUxIDAeBgNVBAsUF0F1dG9yaWRhZCBD
ZXJ0aWZpY2Fkb3JhMRcwFQYDVQQDFA5FLUNFUlRDSElMRSBDQTEjMCEGCSqGSIb3
DQEJARYUZW1haWxAZS1jZXJ0Y2hpbGUuY2wwHhcNMDMxMDAxMTg1ODE1WhcNMDQw
OTMwMDAwMDAwWjCBuDELMAkGA1UEBhMCQ0wxFjAUBgNVBAgUDU1ldHJvcG9saXRh
bmExETAPBgNVBAcUCFNhbnRpYWdvMScwJQYDVQQKFB5TZXJ2aWNpbyBkZSBJbXB1
ZXN0b3MgSW50ZXJub3MxDzANBgNVBAsUBlBpc28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fReWQi
MUEHGGIW</X509Certificate>
</X509Data>
</KeyInfo>
</Signature></EnvioDTE>
This Works. You add "*:" for the nodes.
DECLARE #messagebody XML
SELECT #messagebody = BulkColumn
FROM OPENROWSET(BULK 'C:\Ejemplo.xml', SINGLE_CLOB) AS X
PRINT CONVERT(VARCHAR(MAX),#messagebody)
INSERT INTO [dbo].[Ejemplo24]
select a.value(N'(./*:RutEmisor)[1]', N'nvarchar(12)') as [RutEmisor],
a.value(N'(./*:RutEnvia)[1]', N'nvarchar(12)') as [RutEnvia],
a.value(N'(./*:RutReceptor)[1]', N'nvarchar(12)') as [RutReceptor],
a.value(N'(./*:FchResol)[1]', N'nvarchar(12)') as [FchResol],
a.value(N'(./*:NroResol)[1]', N'nvarchar(12)') as [NroResol]
from #messagebody.nodes('/*:EnvioDTE/*:SetDTE/*:Caratula') as r(a);
Your query is great, but you must specify the default namespace xmlns
Try like this:
WITH XMLNAMESPACES(DEFAULT 'http://www.sii.cl/SiiDte')
INSERT INTO [dbo].[Ejemplo2]
select a.value(N'(./RutEmisor)[1]', N'nvarchar(12)') as [RutEmisor],
a.value(N'(./RutEnvia)[1]', N'nvarchar(12)') as [RutEnvia],
a.value(N'(./RutReceptor)[1]', N'nvarchar(12)') as [RutReceptor],
a.value(N'(./FchResol)[1]', N'nvarchar(12)') as [FchResol],
a.value(N'(./NroResol)[1]', N'nvarchar(12)') as [NroResol]
from #messagebody.nodes('/EnvioDTE/SetDTE/Caratula') as r(a);

XPATH select by set of possible attribute values

I have this:
<database>
<exercise_muscle id="20" muscleID="1" exerciseID="1" />
<exercise_muscle id="35" muscleID="2" exerciseID="1" />
<exercise_muscle id="50" muscleID="3" exerciseID="2" />
<exercise_muscle id="50" muscleID="4" exerciseID="2" />
</database>
And I want to get the exercise_muscle nodes, which have e.g. muscleID value 1, 3 or 4.. so the set of possible values.
I know that I can use "or", but I was hoping there is some better solution.
how about this? (runs using xpath 2.0)
/database/exercise_muscle[#muscleID = ('1', '3', '4')]
alternatively, you can use
/database/exercise_muscle[#muscleID = '1' or #muscleID = '3' or #muscleID = '4']

Need Help XML from text

I have xml from txt file i got strange error(for me)
There is 2 customers and 6 products on the txt file
as is
Result set is
CUSTID ORDER ID
98295 29199752211 0 1 2321
98295 29199752211 0 1 76
98295 29199752211 0 2 179
98295 29199752211 0 3 180
98295 29199752211 0 4 320
98295 29199752211 0 5 NULL
Why the cust id same ? there is 2 in text file. i'll be glad if i can use some help.
SELECT
(SELECT LNGNO FROM ARTUT13.DBO.TBLFATURA WHERE TXTOZELKOD=(c6.value('(//FISLER/FIS/FISID)[1]','VARCHAR(100)'))),--[LNGNO]
0,--[BYTTUR]
c6.value('(KALEMNO)[1]','VARCHAR(100)'),--[LNGKALEMSIRA]
(SELECT LNGKOD FROM ARTUT13.DBO.TBLURUN WHERE TXTKOD=(c6.value('(URUNKODU)[1]','VARCHAR(100)'))),
c6.value('(MIKTAR)[1]','VARCHAR(100)'),--[DBLMIKTAR]
1,--[BYTBIRIMSIRA]
1,--[DBLCEVRIM]
c6.value('(BIRIMFIYAT)[1]','VARCHAR(100)'),--[DBLBIRIMFIYAT]
0,--[BYTKAYITTIP]
0,--[BYTDETAYMAL]
c6.value('(KDV)[1]','VARCHAR(100)'),--[DBLKDVORANI]
c6.value('(FIYAT)[1]','VARCHAR(100)'),--[DBLNETFIYAT]
'',--[TXTOZELKOD]
0,--[LNGVADEGUNU]
GETDATE(),--[TRHSONISLEMTARIHI]
'MUHASEBE2',--[TXTSONISLEMHOST]
'',--[DBLOTV]
c6.value('(//FISLER/FIS/FISID)[1]','VARCHAR(100)'),--[TXTOZELKOD1]
''--[TXTOZELKOD2]
from
(select cast(c1 as xml) from OPENROWSET (BULK 'C:\AKTAR\FATURA.txt',SINGLE_BLOB
) as T1(c1) )as T2(c2)
outer apply c2.nodes('FISLER/FIS/KALEMLER/KALEM') T6(c6)
Text File contains
<FISLER>
<FIS>
<FISTIPI>SATIS</FISTIPI>
<FISID>29199752211</FISID>
<FISNO>a67502</FISNO>
<IPTAL>0</IPTAL>
<TARIH>13.02.2013</TARIH>
<MUSKODU>35170339P</MUSKODU>
<MUSADI>MEHMET PEHLIVAN - MORTAN GIDA MEHMET PEHLIVAN</MUSADI>
<VERGIDAIRESI>KARABURUN MAL MD</VERGIDAIRESI>
<VERGINO>47035582576</VERGINO>
<DEPOKODU>01</DEPOKODU>
<ODEMETIPI>6</ODEMETIPI>
<TOPLAMBRUT>1200.24</TOPLAMBRUT>
<TOPLAMISKONTO>60.01</TOPLAMISKONTO>
<TOPLAMKDV>205.24</TOPLAMKDV>
<TOPLAMNET>1345.47</TOPLAMNET>
<SATISTEMSILCISIKODU>001</SATISTEMSILCISIKODU>
<DAGITICIKODU></DAGITICIKODU>
<ARACKODU></ARACKODU>
<ARACPLAKA></ARACPLAKA>
<SEVKNO></SEVKNO>
<VADETARIHI>06.03.2013</VADETARIHI>
<KALEMLER>
<KALEM>
<KALEMNO>1</KALEMNO>
<URUNKODU>4009011024</URUNKODU>
<URUNADI>EFE KLASİK RAKI45º-100clx12AD TAVA( 63,50 FİYATLI)</URUNADI>
<MIKTAR>24</MIKTAR>
<BIRIMFIYAT>50.01</BIRIMFIYAT>
<FIYAT>1200.24</FIYAT>
<BIRIM></BIRIM>
<KDV>18</KDV>
<ISKONTOLAR>
<ISKONTO>
<price>1200.24</price>
<KODU></KODU>
<ADI>Ürün İsk.1</ADI>
<TIPI></TIPI>
<ORAN>5</ORAN>
<TUTAR>60.012</TUTAR>
</ISKONTO>
</ISKONTOLAR>
</KALEM>
</KALEMLER>
</FIS>
<FIS>
<FISTIPI>SATIS</FISTIPI>
<FISID>29199773107</FISID>
<FISNO>a67511</FISNO>
<IPTAL>0</IPTAL>
<TARIH>13.02.2013</TARIH>
<MUSKODU>100242</MUSKODU>
<MUSADI>NUMBER ONE APART OTEL RESTAURANT</MUSADI>
<VERGIDAIRESI>KARABURUN</VERGIDAIRESI>
<VERGINO>50545253560</VERGINO>
<DEPOKODU>01</DEPOKODU>
<ODEMETIPI>6</ODEMETIPI>
<TOPLAMBRUT>2634.24</TOPLAMBRUT>
<TOPLAMISKONTO>195.21</TOPLAMISKONTO>
<TOPLAMKDV>439.03</TOPLAMKDV>
<TOPLAMNET>2878.06</TOPLAMNET>
<SATISTEMSILCISIKODU>001</SATISTEMSILCISIKODU>
<DAGITICIKODU></DAGITICIKODU>
<ARACKODU></ARACKODU>
<ARACPLAKA></ARACPLAKA>
<SEVKNO></SEVKNO>
<VADETARIHI>06.03.2013</VADETARIHI>
<KALEMLER>
<KALEM>
<KALEMNO>1</KALEMNO>
<URUNKODU>4001017212</URUNKODU>
<URUNADI>EFE YAŞ ÜZÜM RAKISI (45º) - 70 cl 12LI KOLİ</URUNADI>
<MIKTAR>12</MIKTAR>
<BIRIMFIYAT>47.03</BIRIMFIYAT>
<FIYAT>564.36</FIYAT>
<BIRIM></BIRIM>
<KDV>18</KDV>
<ISKONTOLAR>
<ISKONTO>
<price>564.36</price>
<KODU></KODU>
<ADI>Ürün İsk.1</ADI>
<TIPI></TIPI>
<ORAN>10</ORAN>
<TUTAR>56.436</TUTAR>
</ISKONTO>
</ISKONTOLAR>
</KALEM>
<KALEM>
<KALEMNO>2</KALEMNO>
<URUNKODU>4001012324</URUNKODU>
<URUNADI>EFE YAŞ ÜZÜM RAKISI (45º) - 20 cl 24 LU KOLİ</URUNADI>
<MIKTAR>24</MIKTAR>
<BIRIMFIYAT>16.07</BIRIMFIYAT>
<FIYAT>385.68</FIYAT>
<BIRIM></BIRIM>
<KDV>18</KDV>
<ISKONTOLAR>
<ISKONTO>
<price>385.68</price>
<KODU></KODU>
<ADI>Ürün İsk.1</ADI>
<TIPI></TIPI>
<ORAN>10</ORAN>
<TUTAR>38.568</TUTAR>
</ISKONTO>
</ISKONTOLAR>
</KALEM>
<KALEM>
<KALEMNO>3</KALEMNO>
<URUNKODU>4001013724</URUNKODU>
<URUNADI>EFE YAŞ ÜZÜM RAKISI (45º) - 35 cl 24 LU KOLİ</URUNADI>
<MIKTAR>24</MIKTAR>
<BIRIMFIYAT>26.66</BIRIMFIYAT>
<FIYAT>639.84</FIYAT>
<BIRIM></BIRIM>
<KDV>18</KDV>
<ISKONTOLAR>
<ISKONTO>
<price>639.84</price>
<KODU></KODU>
<ADI>Ürün İsk.1</ADI>
<TIPI></TIPI>
<ORAN>10</ORAN>
<TUTAR>63.984</TUTAR>
</ISKONTO>
</ISKONTOLAR>
</KALEM>
<KALEM>
<KALEMNO>4</KALEMNO>
<URUNKODU>4001011013</URUNKODU>
<URUNADI>EFE YAŞ ÜZÜM RAKISI (45º) - 100 cl 12LI TAVA</URUNADI>
<MIKTAR>6</MIKTAR>
<BIRIMFIYAT>60.37</BIRIMFIYAT>
<FIYAT>362.22</FIYAT>
<BIRIM></BIRIM>
<KDV>18</KDV>
<ISKONTOLAR>
<ISKONTO>
<price>362.22</price>
<KODU></KODU>
<ADI>Ürün İsk.1</ADI>
<TIPI></TIPI>
<ORAN>10</ORAN>
<TUTAR>36.222</TUTAR>
</ISKONTO>
</ISKONTOLAR>
</KALEM>
<KALEM>
<KALEMNO>5</KALEMNO>
<URUNKODU>4010017001</URUNKODU>
<URUNADI>EFE 5 YILLIK RAKI45º-70clx3AD KOLİ</URUNADI>
<MIKTAR>6</MIKTAR>
<BIRIMFIYAT>113.69</BIRIMFIYAT>
<FIYAT>682.14</FIYAT>
<BIRIM></BIRIM>
<KDV>18</KDV>
</KALEM>
</KALEMLER>
</FIS>
</FISLER>
1) Your question is not clear: how can be extracted CUSTID from that XML ? There is not CUSTID element in that XML.
2) Very likely, the cause is (if I look at your source code) the usage of absolute references (.value('(//element...)[1]',...)) instead of relative references (.value('(element...)[1]',...)).
Sample:
DECLARE #x XML;
SET #x = N'<...>';
SELECT c6.value('(//FISLER/FIS/FISID)[1]','VARCHAR(100)') AS AbsoluteRef_FISID
FROM #x.nodes('FISLER/FIS/KALEMLER/KALEM') T6(c6)
SELECT c6.value('(FISID)[1]','VARCHAR(100)') AS RelativeRef_FISID
FROM #x.nodes('FISLER/FIS') T6(c6)
Results:
AbsoluteRef_FISID
-------------------
29199752211
29199752211
29199752211
29199752211
29199752211
29199752211
RelativeRef_FISID
-------------------
29199752211
29199773107
// means absolute references and c6.value('(//FISLER/FIS/FISID)[1]','VARCHAR(100)') will extract only the first ([1]) FISID value from that XML.
.value('(FISID)[1]',...) uses a relative reference (relative to nodes('FISLER/FIS') T6(c6)) and the result will contains all FISID values.
If your run this query
SELECT c6.query('.') AS XmlNode
FROM #x.nodes('FISLER/FIS') T6(c6);
you will get two rows meaning that .nodes('FISLER/FIS') will extract two rows
XmlNode
----------------------------------------------------------------------------
<FIS><FISTIPI>SATIS</FISTIPI><FISID>29199752211</FISID><FISNO>a67502</FISNO>
<FIS><FISTIPI>SATIS</FISTIPI><FISID>29199773107</FISID><FISNO>a67511</FISNO>
from #x XML variable. Starting from this point (two rows), the value method .value('(FISID)[1]',...) will extract the first FISID ((FISID)[1]) for every row. Thus, you will get two FISID values.
SQLFiddle demo

Resources