删除重复且真正冗余的命名空间
在下面的代码中这个语句;
declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd
重复 6 次,使代码变得非常混乱且难以理解:
SELECT XW_PK, xw_ExeVersion, xw_enterpriseCode, xw_DatabaseCode, xw_CompanyCode,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@name)[1]', 'varchar(100)') Name,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@started)[1]', 'varchar(100)') [Started],
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@ended)[1]', 'varchar(100)') [Ended],
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@Elapsed)[1]', 'varchar(100)') Elapsed,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@elapsedWithChildren)[1]', 'varchar(100)') elapsedWithChildren
FROM stmusage
CROSS APPLY xw_rawData.nodes('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
/pd:performanceMeasurement/pd:action') as Poodle(Love)
我想要做的就是仅声明一次命名空间并完成它。问题是每个 xqueries 都嵌入在一个字符串中 - 我不完全确定 - 但我多年来获得的经验给我压倒性的印象,即这些字符串不会与每个字符串交互很快就会有其他的。
In the following code this statement;
declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd
is repeated 6 times making the code really messy and harder to follow:
SELECT XW_PK, xw_ExeVersion, xw_enterpriseCode, xw_DatabaseCode, xw_CompanyCode,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@name)[1]', 'varchar(100)') Name,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@started)[1]', 'varchar(100)') [Started],
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@ended)[1]', 'varchar(100)') [Ended],
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@Elapsed)[1]', 'varchar(100)') Elapsed,
Poodle.Love.value('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@elapsedWithChildren)[1]', 'varchar(100)') elapsedWithChildren
FROM stmusage
CROSS APPLY xw_rawData.nodes('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
/pd:performanceMeasurement/pd:action') as Poodle(Love)
What I want to do is declare the namespace just once and be done with it. The problem is that each of the xqueries are embedded in a string - and I'm not completely sure - but the experiece I've picked up over the years gives me the overwhelming impression that these strings aren't going to be interacting with each other any time soon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你正在编写的编程语言,但在任何其他语言中,我会编写一个函数,将字符串“name”或“started”作为参数 PPPPPP 并生成
Poodle.Love.value('declare namespace d ="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@{PPPPPP})[1]', 'varchar(100)')
作为其结果。
I don't know the programming language you are writing in, but in any other language I would write a function that takes the string "name" or "started" as a parameter PPPPP and produces
Poodle.Love.value('declare namespace d="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
(pd:action/@{PPPPP})[1]', 'varchar(100)')
as its result.
简单!
Easy as!