删除重复且真正冗余的命名空间

发布于 2024-12-10 13:07:57 字数 1422 浏览 0 评论 0原文

在下面的代码中这个语句;

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖正好 2024-12-17 13:07:57

我不知道你正在编写的编程语言,但在任何其他语言中,我会编写一个函数,将字符串“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.

囍笑 2024-12-17 13:07:57
SELECT 
            XMLTable.actions.value('(@name)', 'varchar(100)') Name,
            XMLTable.actions.value('(@started)', 'datetime') [Started],
            XMLTable.actions.value('(@started)', 'datetime') + 
            convert(float, replace (replace (XMLTable.actions.value('(@elapsedWithChildren)', 'varchar(100)'),'PT',''),'S','')) / (60 * 60 * 24) Ended, --dodgy floating point rounding errors
            convert(float, replace (replace (XMLTable.actions.value('(@elapsed)', 'varchar(100)'),'PT',''),'S','')) Elapsed,
            convert(float, replace (replace (XMLTable.actions.value('(@elapsedWithChildren)', 'varchar(100)'),'PT',''),'S','')) ElapsedWithChildren,
            XMLTable.actions.value('@moduleId','varchar(100)') moduleid,
            XMLTable.actions.value('@actionCount','int') actionCount,
            XW_PK, XW_ExeVersion, XW_EnterpriseCode, XW_DatabaseCode, XW_CompanyCode, ExportType
            FROM StmUsage
                CROSS APPLY xw_rawData.nodes('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
                /pd:performanceMeasurement/pd:action') XMLTable(actions)
            cross join (select 'Elapsed' ExportType union select 'ElapsedWithChildren') ExportTypeAlias

简单!

SELECT 
            XMLTable.actions.value('(@name)', 'varchar(100)') Name,
            XMLTable.actions.value('(@started)', 'datetime') [Started],
            XMLTable.actions.value('(@started)', 'datetime') + 
            convert(float, replace (replace (XMLTable.actions.value('(@elapsedWithChildren)', 'varchar(100)'),'PT',''),'S','')) / (60 * 60 * 24) Ended, --dodgy floating point rounding errors
            convert(float, replace (replace (XMLTable.actions.value('(@elapsed)', 'varchar(100)'),'PT',''),'S','')) Elapsed,
            convert(float, replace (replace (XMLTable.actions.value('(@elapsedWithChildren)', 'varchar(100)'),'PT',''),'S','')) ElapsedWithChildren,
            XMLTable.actions.value('@moduleId','varchar(100)') moduleid,
            XMLTable.actions.value('@actionCount','int') actionCount,
            XW_PK, XW_ExeVersion, XW_EnterpriseCode, XW_DatabaseCode, XW_CompanyCode, ExportType
            FROM StmUsage
                CROSS APPLY xw_rawData.nodes('declare namespace pd="http://cargowise.com/ediEnterprise/2011/10/11/systemUsage.xsd";
                /pd:performanceMeasurement/pd:action') XMLTable(actions)
            cross join (select 'Elapsed' ExportType union select 'ElapsedWithChildren') ExportTypeAlias

Easy as!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文