我有这样的XML
<OrchestrationConfiguration>
<Instrument>
<Spectrometer>
<Inputs>
<Channel-ChannelNumber-1>
<ChannelNumber>1</ChannelNumber>
<ChannelName>Answer01</ChannelName>
</Channel-ChannelNumber-1>
</Inputs>
<Outputs>
<Channel-ChannelNumber-1>
<ChannelNumber>1</ChannelNumber>
<ChannelName>1</ChannelName>
<ChannelName>2</ChannelName>
<ChannelName>3</ChannelName>
<ChannelName>4</ChannelName>
<ChannelName>5</ChannelName>
<ChannelName>6</ChannelName>
<ChannelName>7</ChannelName>
<ChannelName>8</ChannelName>
<ChannelName>9</ChannelName>
<ChannelName>10</ChannelName>
</Channel-ChannelNumber-1>
<Channel-ChannelNumber-2>
<ChannelNumber>2</ChannelNumber>
<ChannelName>Temperature-K</ChannelName>
</Channel-ChannelNumber-2>
<Channel-ChannelNumber-3>
<ChannelNumber>3</ChannelNumber>
<ChannelName>Pressure-inHg-absolute</ChannelName>
</Channel-ChannelNumber-3>
</Outputs>
</Spectrometer>
</OrchestrationConfiguration>
在我的SSRS报告中。我创建了一个按父名称分组的列表,并获取我已应用以下过滤器
的输出我遇到的问题是获取输入。我无法区分输出和输入,因为过滤器是相同的。有没有其他方法这样做?如果需要,我很乐意更改XML的格式。
我正在使用XMLTable函数来粉碎xml。 Shred XML
答案 0 :(得分:0)
在您的评论中,您声明可以更改XML。你真的应该这样做。
一些背景知识:
<Channel>
下面的所有<Outputs>
元素,但它需要hacky变通方法来询问显示<Outputs>
以下的所有元素以Channel
开头的名称。 试试这样:
DECLARE @XML XML=
'<OrchestrationConfiguration>
<Instrument>
<Spectrometer>
<Inputs>
<Channel Number="1">
<ChannelName>Answer01</ChannelName>
</Channel>
</Inputs>
<Outputs>
<Channel Number="1">
<ChannelName>1</ChannelName>
<ChannelName>2</ChannelName>
<ChannelName>3</ChannelName>
<ChannelName>4</ChannelName>
<ChannelName>5</ChannelName>
<ChannelName>6</ChannelName>
<ChannelName>7</ChannelName>
<ChannelName>8</ChannelName>
<ChannelName>9</ChannelName>
<ChannelName>10</ChannelName>
</Channel>
<Channel Number="2">
<ChannelName>Temperature-K</ChannelName>
</Channel>
<Channel Number="3">
<ChannelName>Pressure-inHg-absolute</ChannelName>
</Channel>
</Outputs>
</Spectrometer>
</Instrument>
</OrchestrationConfiguration>';
- 我不知道你是如何需要数据的,但是SQL-Server
我实现了一个内联表值函数,传入XML并检索数据派生表。使用这样的东西:
SELECT InpCh.value('@Number','int') AS InputChannelNumber
,InpCh.value('(ChannelName/text())[1]','nvarchar(max)') AS InputChannelName
,OutCh.value('@Number','int') AS InputChannelNumber
,OutChName.value('(text())[1]','nvarchar(max)') AS InputChannelName
FROM @xml.nodes('/OrchestrationConfiguration/Instrument/Spectrometer/Inputs/Channel') AS A(InpCh)
OUTER APPLY @xml.nodes('/OrchestrationConfiguration/Instrument/Spectrometer/Outputs/Channel') AS B(OutCh)
OUTER APPLY B.OutCh.nodes('ChannelName') AS C(OutChName)