I'm trying to implement factorial in an xml language - factorial

I'm trying to implement factorial in the xml language of xcerion.
<step id="fac">
<alias name="p" value="={$n}*{$p}" />
<alias name="n" value="={$n}-1" />
<operation name="decision">
<when test="'{$n}'>'0'" step="fac" />
</operation>
</step>
<alias name="p" value="1" />
<alias name="n" value="4" />
<operation name="call" value="fac" />
My code works, but I think it's a bit wordy.
How does this language compare with other xml languages?
Especially handling of variables, selection, loops and subroutine calling.

Related

How to update empty XML node in MSSQL

I want to update empty XML variable in MSSQL
i try every solutions like replace, outer apply , modify but nothing working
please help me find a solutions
<ArrayOfField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Field>
<FieldType>1</FieldType>
<DataType>1</DataType>
<Label>department</Label>
<Name>department</Name>
<Description />
<Min />
<Max />
<DefaultValue />
<Required>0</Required>
<SelectItems />
<Formula />
<DataSourceUID xsi:nil="true" />
<TrueText />
<FalseText />
<UnconfirmtyRule xsi:nil="true" />
<UnconfirmtyRequired xsi:nil="true" />
<UnconfirmityFormUID xsi:nil="true" />
<ConfirmationStatus xsi:nil="true" />
<ConfirmationUserBasedType xsi:nil="true" />
<ConfirmationRightUsers />
<Newline>false</Newline>
<ColumnWith>12</ColumnWith>
<Offset>0</Offset>
</Field>
<Field>
<FieldType>1</FieldType>
<DataType>4</DataType>
<Label>Test</Label>
<Name>test</Name>
<Description />
<Min />
<Max />
<DefaultValue />
<Required>0</Required>
<SelectItems />
<Formula />
<TrueText />
<FalseText />
<UnconfirmtyRule xsi:nil="true" />
<UnconfirmtyRequired xsi:nil="true" />
<UnconfirmityFormUID xsi:nil="true" />
<ConfirmationStatus xsi:nil="true" />
<ConfirmationUserBasedType xsi:nil="true" />
<ConfirmationRightUsers />
<Newline>false</Newline>
<ColumnWith>12</ColumnWith>
<Offset>0</Offset>
</Field>
</ArrayOfField>
I want update DefaultValue if DataType = 1
New DefaultValue like <DefaultValue>TODAY()<DefaultValue/>
I try this code but not update anything what is my mistake?
DECLARE #SearchType NVARCHAR(100)=N'1';
DECLARE #ReplaceWith NVARCHAR(100)=N'TODAY()';
UPDATE FormSchema
SET Fields.modify('replace value of
(/ArrayOfField
/Field[DataType=sql:variable("#SearchType")]
/DefaultValue/text())[1]
with sql:variable("#ReplaceWith")')
WHERE Fields.exist('/ArrayOfField
/Field[DataType=sql:variable("#SearchType")]')=1;
You need to use different XML modify operations depending on whether the target element is empty or not (i.e.: it contains no text as opposed to being xsi:nil="true"). For example...
--
-- Setup data...
--
create table dbo.FormSchema (
Fields xml
);
insert dbo.FormSchema (Fields) values
(N'<ArrayOfField>
<Field>
<DataType>1</DataType>
<DefaultValue>Hello, world!</DefaultValue>
</Field>
<Field>
<DataType>2</DataType>
<DefaultValue />
</Field>
</ArrayOfField>'),
(N'<ArrayOfField>
<Field>
<DataType>1</DataType>
<DefaultValue />
</Field>
<Field>
<DataType>3</DataType>
<DefaultValue />
</Field>
</ArrayOfField>');
--
-- Perform updates...
--
DECLARE
#SearchType NVARCHAR(100) = N'1',
#ReplaceWith NVARCHAR(100) = N'TODAY()';
UPDATE dbo.FormSchema
SET Fields.modify('
replace value of (/ArrayOfField/Field[DataType=sql:variable("#SearchType")]/DefaultValue/text())[1]
with sql:variable("#ReplaceWith")
')
WHERE Fields.exist('(/ArrayOfField/Field[DataType=sql:variable("#SearchType")]/DefaultValue/text())[1]')=1;
UPDATE dbo.FormSchema
SET Fields.modify('
insert text{sql:variable("#ReplaceWith")}
into (/ArrayOfField/Field[DataType=sql:variable("#SearchType")]/DefaultValue)[1]
')
WHERE Fields.exist('(/ArrayOfField/Field[DataType=sql:variable("#SearchType")]/DefaultValue)[1]')=1
AND Fields.exist('(/ArrayOfField/Field[DataType=sql:variable("#SearchType")]/DefaultValue/text())[1]')=0;
--
-- Check results...
--
SELECT * FROM dbo.FormSchema;
Which yields the results:
Fields
<ArrayOfField><Field><DataType>1</DataType><DefaultValue>TODAY()</DefaultValue></Field><Field><DataType>2</DataType><DefaultValue /></Field></ArrayOfField>
<ArrayOfField><Field><DataType>1</DataType><DefaultValue>TODAY()</DefaultValue></Field><Field><DataType>3</DataType><DefaultValue /></Field></ArrayOfField>

SQL Server xml query doesn't return expected result

I have a column in my database FlowDetailParameter with XML Type .My table has one column FlowDetailParameter and 3 rows with these data :
row 1
<ArrayOfFlowDetailParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FlowDetailParameters>
<DepartmentId>7</DepartmentId>
<UserId>6</UserId>
<Username>4</Username>
<FullName>کارشناس معاینه فنی</FullName>
<ConfirmDateTime>2018-11-01T10:45:29.7371421+03:30</ConfirmDateTime>
<Comment>اولین IP تاییدی</Comment>
<Status>Accept</Status>
</FlowDetailParameters>
<FlowDetailParameters>
<DepartmentId>3</DepartmentId>
<UserId xsi:nil="true" />
<Username />
<FullName />
<ConfirmDateTime xsi:nil="true" />
<Comment />
<Status>Pending</Status>
<AttachmentId />
</FlowDetailParameters>
</ArrayOfFlowDetailParameters>
row 2
<ArrayOfFlowDetailParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FlowDetailParameters>
<DepartmentId>7</DepartmentId>
<UserId>6</UserId>
<Username>4</Username>
<FullName>کارشناس معاینه فنی</FullName>
<ConfirmDateTime>2018-11-01T10:45:40.437481+03:30</ConfirmDateTime>
<Comment>دومین IP تاییدی</Comment>
<Status>Accept</Status>
</FlowDetailParameters>
<FlowDetailParameters>
<DepartmentId>3</DepartmentId>
<UserId xsi:nil="true" />
<Username />
<FullName />
<ConfirmDateTime xsi:nil="true" />
<Comment />
<Status>Pending</Status>
<AttachmentId />
</FlowDetailParameters>
</ArrayOfFlowDetailParameters>
row 3
<ArrayOfFlowDetailParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<FlowDetailParameters>
<DepartmentId>7</DepartmentId>
<UserId xsi:nil="true" />
<Username />
<FullName />
<ConfirmDateTime xsi:nil="true" />
<Comment />
<Status>Pending</Status>
<AttachmentId />
</FlowDetailParameters>
<FlowDetailParameters>
<DepartmentId>3</DepartmentId>
<UserId xsi:nil="true" />
<Username />
<FullName />
<ConfirmDateTime xsi:nil="true" />
<Comment />
<Status />
<AttachmentId />
</FlowDetailParameters>
</ArrayOfFlowDetailParameters>
I want to find the departmentId=3 and status=Pending ,so the expected result should return 2 rows .So here is my query :
select Requests.* from Requests
where
((SELECT count(*)
FROM Requests t
CROSS APPLY t.FlowDetailParameter.nodes ('/ArrayOfFlowDetailParameters/FlowDetailParameters') x(v)
where x.v.value('(DepartmentId/text())[1]', 'bigint')=3 and x.v.value('(Status/text())[1]', 'varchar(50)') = 'Pending') >0)
But my query returns all rows (3 rows) why ?
First to answer your question "why?":
Your sub-query is not a correlated sub-query. There is no connection to the current row from the outer SELECT. So - assuming there is at least 1 row fulfilling your condition - this will always provide a count>0.
Although your approach can be corrected, I'd suggest to use the XML-method .exist() and provide the filter as XPath/XQuery:
SELECT *
FROM Requests r
WHERE r.FlowDetailParameter.exist(N'/ArrayOfFlowDetailParameters
/FlowDetailParameters[(DepartmentId/text())[1]=3
and (Status/text())[1]="Pending"]')=1;
This will check for the existance of any <FlowDetailParameters> for the given condition.
If you want to introduce the filter dynamically, you can use sql:variable() or sql:column() instead of 3 and "Pending"
DECLARE #depId INT=3;
DECLARE #status VARCHAR(100)='Pending';
SELECT *
FROM Requests r
WHERE r.FlowDetailParameter.exist(N'/ArrayOfFlowDetailParameters
/FlowDetailParameters[(DepartmentId/text())[1]=sql:variable("#depId")
and (Status/text())[1]=sql:variable("#status")]')=1

Problems querying

I'm trying to query the following XML the way I always do, but due to its declaration and the empty "NextQuantity" - "NextDate" fields, I'm having troubles querying the XML.
What's the right way to do this?
Thank you.
<StocksResp xmlns="http://xxxxxx" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Stocks>
<Stock>
<Sku>30101.06-L</Sku>
<Quantity>247610</Quantity>
<NextQuantity1>15243</NextQuantity1>
<NextDate1>2019-02-27</NextDate1>
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
<Stock>
<Sku>30101.06-M</Sku>
<Quantity>241606</Quantity>
<NextQuantity1 i:nil="true" />
<NextDate1 />
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
</Stocks>
<Count>4837</Count>
<Currency i:nil="true" />
<Language>ES</Language>
<ErrorCode i:nil="true" />
<ErrorMessage i:nil="true" />
</StocksResp>
===============================================
DECLARE #xml XML
SELECT #xml = x.y FROM OPENROWSET (BULK 'file.xml',SINGLE_BLOB) as x(y)
SELECT
x.y.value('Sku[1]','varchar(15)'),
x.y.value('Quantity[1]','int'),
x.y.value('NextDate1[1]','varchar(20)'),
x.y.value('NextQuantity1[1]','int'),
'mr'
FROM #xml.nodes('Stocks/Stock') x(y)
Might this help?
DECLARE #xml XML=
N'<StocksResp xmlns="http://xxxxxx" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Stocks>
<Stock>
<Sku>30101.06-L</Sku>
<Quantity>247610</Quantity>
<NextQuantity1>15243</NextQuantity1>
<NextDate1>2019-02-27</NextDate1>
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
<Stock>
<Sku>30101.06-M</Sku>
<Quantity>241606</Quantity>
<NextQuantity1 i:nil="true" />
<NextDate1 />
<NextQuantity2 i:nil="true" />
<NextDate2 />
<NextQuantity3 i:nil="true" />
<NextDate3 />
<NextQuantity4 i:nil="true" />
<NextDate4 />
<NextQuantity5 i:nil="true" />
<NextDate5 />
<NextQuantity6 i:nil="true" />
<NextDate6 />
</Stock>
</Stocks>
<Count>4837</Count>
<Currency i:nil="true" />
<Language>ES</Language>
<ErrorCode i:nil="true" />
<ErrorMessage i:nil="true" />
</StocksResp>';
-You need to declare the default namespace. You would not need to declare the namespace i...
WITH XMLNAMESPACES(DEFAULT 'http://xxxxxx','http://www.w3.org/2001/XMLSchema-instance' AS i)
SELECT
#xml.value(N'(/StocksResp/Count/text())[1]',N'int') AS StockResp_Count
,#xml.value(N'(/StocksResp/Currency/text())[1]',N'int') AS StockResp_Currency
,st.value(N'(Sku/text())[1]',N'nvarchar(max)') AS Stock_Sku
,st.value(N'(Quantity/text())[1]',N'int') AS Stock_Quantity
,st.value(N'(NextQuantity1/text())[1]',N'int') AS Stock_NextQuantity1
,st.value(N'(NextDate1/text())[1]',N'date') AS Stock_NextDate1
,st.value(N'(NextQuantity2/text())[1]',N'int') AS Stock_NextQuantity2
,st.value(N'(NextDate2/text())[1]',N'date') AS Stock_NextDate2
,st.value(N'(NextQuantity3/text())[1]',N'int') AS Stock_NextQuantity3
,st.value(N'(NextDate3/text())[1]',N'date') AS Stock_NextDate3
,st.value(N'(NextQuantity4/text())[1]',N'int') AS Stock_NextQuantity4
,st.value(N'(NextDate4/text())[1]',N'date') AS Stock_NextDate4
,st.value(N'(NextQuantity5/text())[1]',N'int') AS Stock_NextQuantity5
,st.value(N'(NextDate5/text())[1]',N'date') AS Stock_NextDate5
,st.value(N'(NextQuantity6/text())[1]',N'int') AS Stock_NextQuantity6
,st.value(N'(NextDate6/text())[1]',N'date') AS Stock_NextDate6
FROM #xml.nodes('/StocksResp/Stocks/Stock') A(st);
Some remarks:
It is a very bad habit to name-number elements (Date1, Date2 and so on). If you can change this, you should use a nested set of elements and number them eiter by their position or with an attribute like
<Next index="1">
<Date>2018-01-01</Date>
<Quantity>1</Quantity>
</Next>
[... more of them ...]
you can see, that I read the just-once values directly from the variable, while the repeating elements are taken from a derived table by .nodes().

OPENXML not returning data, no error message

I've never worked with XML before but have been tasked to import a document into a SQL Server table. As a test, I'm been using an example I found online and, for now, I'm only trying to retrieve a single column:
DECLARE #X XML
SELECT #X=MC2016
FROM OPENROWSET (BULK 'C:\TEMP\Detail_2016.xml', SINGLE_BLOB) AS MEDPOP_2016(MC2016)
DECLARE #hdoc int
EXEC SP_XML_PREPAREDOCUMENT #hdoc OUTPUT, #X
select *
from openxml (#hdoc, '/Results/Record', 1)
with (
MemberID varchar(10)
)
EXEC SP_XML_REMOVEDOCUMENT #hdoc
When I execute this in SSMS, the query completes but I get zero rows of output even though I know that there are many thousands of records.
I'm running SQL Server 2016. The XML file is too large include here but here's the first record (deidentified):
<?xml version="1.0" encoding="utf-8"?>
<Results xmlns="http://www.dxcg.com/Results.xsd">
<Record MemberID="0012345" DOB="1917-09-09" Age="100" Gender="M" Child="0" Elderly="1" Male="1" AgeGender="34" NoHCC="false" NoValid="false" NoDiag="false" NoRxGroup="true" NoValidRx="false" ELG1="12" ELIGF1="1" ECAT="-1" MCAID="0" OREC="0" EXP1="33.78" ExpRx1="0.00">
<Groups>
<Group Name="FSC" Value="99" />
</Groups>
<Period Name="Base">
<Classifier Type="Standard">
<DxGs>
<DxG ID="887" />
<DxG ID="638" />
<DxG ID="910" />
<DxG ID="911" />
<DxG ID="716" />
<DxG ID="534" />
<DxG ID="530" />
<DxG ID="61" />
</DxGs>
<CCs>
<CC ID="266" HierarchyY1="true" HierarchyY2="true" />
<CC ID="230" HierarchyY1="true" HierarchyY2="true" />
<CC ID="19" HierarchyY1="true" HierarchyY2="true" />
<CC ID="349" HierarchyY1="false" HierarchyY2="true" />
<CC ID="231" HierarchyY1="false" HierarchyY2="false" />
<CC ID="347" HierarchyY1="true" HierarchyY2="false" />
<CC ID="293" HierarchyY1="true" HierarchyY2="true" />
</CCs>
<RCCs>
<RCC ID="77" HierarchyY1="true" HierarchyY2="true" />
<RCC ID="62" HierarchyY1="true" HierarchyY2="true" />
<RCC ID="2" HierarchyY1="true" HierarchyY2="true" />
<RCC ID="103" HierarchyY1="true" HierarchyY2="true" />
<RCC ID="87" HierarchyY1="true" HierarchyY2="true" />
</RCCs>
<ACCs>
<ACC ID="19" HierarchyY1="true" HierarchyY2="true" />
<ACC ID="16" HierarchyY1="true" HierarchyY2="true" />
<ACC ID="2" HierarchyY1="true" HierarchyY2="true" />
<ACC ID="27" HierarchyY1="true" HierarchyY2="true" />
<ACC ID="22" HierarchyY1="true" HierarchyY2="true" />
</ACCs>
<RxGs />
<ARxGs />
</Classifier>
</Period>
<DCGs>
<DCG ID="2" Value="0.5" />
</DCGs>
<ADCGs>
<ADCG ID="2" Value="0.5" />
</ADCGs>
<Preds>
<Pred ID="122" Value="1.6393262810427782" />
<Pred ID="2" Value="0.55220631651432173">
<RiskDriver Label="" HCC="293" Contribution="68.537299593489152" />
<RiskDriver Label="" HCC="230" Contribution="18.964637260918547" />
<RiskDriver Label="" HCC="347" Contribution="5.12631266098848" />
<RiskDriver Label="" HCC="266" Contribution="4.43513850335468" />
<RiskDriver Label="" HCC="19" Contribution="2.936611981249146" />
</Pred>
</Preds>
</Record>
Ultimately, I want to load this entire record into a table but as of now, I can't even read a single column and I'm not getting any error messages to point me in a direction to look.
What am I missing here? Thanks.
Best regards,
Corey
Starting from the code from the link provided in the comments you can use this code:
DECLARE #X XML
SELECT #X=MC2016
FROM OPENROWSET (BULK 'c:\TEMP\Detail_2016.xml', SINGLE_BLOB) AS MEDPOP_2016(MC2016)
DECLARE #hdoc int
EXEC SP_XML_PREPAREDOCUMENT #hdoc OUTPUT, #X, '<myNs xmlns:ns1="http://www.dxcg.com/Results.xsd"/>'
;WITH XMLNAMESPACES ('http://www.dxcg.com/Results.xsd' as ns1)
select *
from openxml (#hdoc, '/ns1:Results/ns1:Record', 1)
with (
MemberID varchar(10)
)
Results:
Note: the xml you posted is probably missing a the closing tag for root element </Results>

Parsing XML in T-SQL - ABS data

I'm after some assistance parsing an xml file provided by the Australian Bureau of Statistics. I've read over everything I can find here and online, and am not having much luck reading this data.
This is a sample of the XML:
<?xml version='1.0' encoding='UTF-8'?>
<message:MessageGroup xmlns:message="http://www.w3.org/2001/XMLSchema" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic http://www.sdmx.org/docs/2_0/SDMXGenericData.xsd http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message http://www.sdmx.org/docs/2_0/SDMXMessage.xsd">
<Header xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message">
<ID>none</ID>
<Test>false</Test>
<Truncated>false</Truncated>
<Prepared>2018-02-14T22:41:03</Prepared>
<Sender id="ABS">
<Name xml:lang="en">Australian Bureau of Statistics</Name>
<Name xml:lang="fr">Australian Bureau of Statistics</Name>
</Sender>
</Header>
<DataSet keyFamilyURI="http://stat.data.abs.gov.au/restsdmx/sdmx.ashx/GetKeyFamily/RES_PROP_INDEX">
<KeyFamilyRef>RES_PROP_INDEX</KeyFamilyRef>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="3GBRI" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="112.7" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.7" />
</Obs>
</Series>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="5GPER" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="114.4" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.4" />
</Obs>
</Series>
<Annotations>
<common:Annotation>
<common:AnnotationTitle>Statistical usage warning</common:AnnotationTitle>
<common:AnnotationText>ABS.Stat beta is continuing to be developed. Data will be updated as soon as possible following its 11:30 am release on the ABS website.</common:AnnotationText>
</common:Annotation>
</Annotations>
</DataSet>
</message:MessageGroup>
The result set should return 3 values:
SeriesKey Value where Concept = 'ASGS_2011'
Obs "Time" Value
Obs "Obsvalue" Value
e.g the first record would return a row like:
3GBRI | 2015-Q1 | 112.7
This sample would return 4 rows of data like this.
I've tried inserting the XML into an XML variable or a column in a DB with an XML datatype, and then using SQL's XML functionality, but I'm an absolute novice at this and am having trouble with the correct coding/approach.
Any advice or sample code would be greatly appreciated.
I'd suggest do get rid of the <?xml blah ?> declaration. This is only useful when you store an XML to a file. Within SQL-Server any XML's encoding is fixed to unicode / UCS-2. This can lead to encoding problems...
There are namespaces involved...
DECLARE #xml XML=
'<?xml version=''1.0'' encoding=''UTF-8''?>
<message:MessageGroup xmlns:message="http://www.w3.org/2001/XMLSchema" xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic" xmlns:common="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic http://www.sdmx.org/docs/2_0/SDMXGenericData.xsd http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message http://www.sdmx.org/docs/2_0/SDMXMessage.xsd">
<Header xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message">
<ID>none</ID>
<Test>false</Test>
<Truncated>false</Truncated>
<Prepared>2018-02-14T22:41:03</Prepared>
<Sender id="ABS">
<Name xml:lang="en">Australian Bureau of Statistics</Name>
<Name xml:lang="fr">Australian Bureau of Statistics</Name>
</Sender>
</Header>
<DataSet keyFamilyURI="http://stat.data.abs.gov.au/restsdmx/sdmx.ashx/GetKeyFamily/RES_PROP_INDEX">
<KeyFamilyRef>RES_PROP_INDEX</KeyFamilyRef>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="3GBRI" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="112.7" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.7" />
</Obs>
</Series>
<Series>
<SeriesKey>
<Value concept="MEASURE" value="1" />
<Value concept="PROP_TYPE" value="3" />
<Value concept="ASGS_2011" value="5GPER" />
<Value concept="FREQUENCY" value="Q" />
</SeriesKey>
<Attributes>
<Value concept="TIME_FORMAT" value="P3M" />
</Attributes>
<Obs>
<Time>2015-Q1</Time>
<ObsValue value="114.4" />
</Obs>
<Obs>
<Time>2015-Q2</Time>
<ObsValue value="113.4" />
</Obs>
</Series>
<Annotations>
<common:Annotation>
<common:AnnotationTitle>Statistical usage warning</common:AnnotationTitle>
<common:AnnotationText>ABS.Stat beta is continuing to be developed. Data will be updated as soon as possible following its 11:30 am release on the ABS website.</common:AnnotationText>
</common:Annotation>
</Annotations>
</DataSet>
</message:MessageGroup>';
--The query will declare the needed namespaces and then use .nodes() to get the <Series> and a second call to .nodes() to get the nested <Obs>:
WITH XMLNAMESPACES(DEFAULT 'http://www.SDMX.org/resources/SDMXML/schemas/v2_0/generic'
,'http://www.w3.org/2001/XMLSchema' AS message)
SELECT ser.value(N'(SeriesKey/Value[#concept="ASGS_2011"]/#value)[1]',N'nvarchar(max)') AS Concept
,obs.value(N'(Time/text())[1]',N'nvarchar(max)') AS [Time]
,obs.value(N'(ObsValue/#value)[1]',N'decimal(10,4)') AS ObsValue
FROM #xml.nodes(N'/message:MessageGroup/DataSet/Series') AS A(ser)
OUTER APPLY A.ser.nodes(N'Obs') AS B(obs);
The result
Concept Time ObsValue
3GBRI 2015-Q1 112.7000
3GBRI 2015-Q2 113.7000
5GPER 2015-Q1 114.4000
5GPER 2015-Q2 113.4000

Resources