Is @mp:id always in order of the XML Doc?
I am parsing some xml using OPENXML. I need to get an Identity off of the XML to know the order of the nodes.
is @mp:id always in order?开发者_开发技巧 I know they are not sequential, but are they at least in order?
For example would the following query always produce results in the exact same order as the XML?
SELECT row_number() OVER (ORDER BY OrderID) rn,
StepID, CONVERT(varchar(max), CONVERT(VARBINARY(max), StepID), 2),
[ACTION]
FROM OPENXML(@idoc, 'descendant::step |descendant::compref', 2)
WITH ([OrderID] INT '@mp:id',
[StepID] INT '@id',
[Action] VARCHAR(max) 'parameterizedString[1]')
ORDER BY rn
or is @mp:id a meta data kind of thing that could go in any order based on how things are saved?
You have no guarantee of right order. To have it, you can generate numbers sequence (eg NF table with column Number) and then query your XML using XPath with position() function:
SELECT NF.Number,Order_id FROM NF
CROSS APPLY(SELECT Table.Row.value('@Id','int') Order_Id
FROM @xml.nodes('//Root/Order[position()=sql:column("NF.Number")]') AS Table(Row)) AS XMLTable
精彩评论