如何解析这个 XML 文档?

问题描述 投票:0回答:0

我在 SQL 表的一列中有 XML,我运行的每个查询都返回 null。我试过将 XML 复制到记事本并将其另存为 XML 文件,然后通过 PowerShell 访问它。这是它的副本:

<?xml version="1.0" encoding="utf-16"?>
< AppMgmtDigest xmlns="http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDigest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

不得不用上面的模式这样写,因为它没有显示为可查看的代码*

<Application AuthoringScopeId="ScopeId_932201A0-0C33-4C2C-9723-2975C4CCEBB5" LogicalName="Application_0e2a35f6-49a1-403f-adf5-d9f393571943" Version="4">
<DisplayInfo DefaultLanguage="en-US">
<Info Language="en-US">
<Title>Microsoft Office Excel Viewer</Title>
</Info>
</DisplayInfo>
<DeploymentTypes>
<DeploymentType AuthoringScopeId="ScopeId_932201A0-0C33-4C2C-9723-2975C4CCEBB5" LogicalName="DeploymentType_04fa8891-e832-486f-8d72-fc77c7dcffda" Version="3"/>
</DeploymentTypes>
<Title ResourceId="Res_1963789643">Microsoft Office Excel Viewer</Title>
<AutoInstall>true</AutoInstall>
<Owners>
<User Qualifier="LogonName" Id="abc123"/>
</Owners>
<Contacts>
<User Qualifier="LogonName" Id="abc123"/>
</Contacts>
</Application>
<DeploymentType AuthoringScopeId="ScopeId_932201A0-0C33-4C2C-9723-2975C4CCEBB5" LogicalName="DeploymentType_04fa8891-e832-486f-8d72-fc77c7dcffda" Version="3">
...
</DeploymentType>
</AppMgmtDigest>

我无法查询这份文件。在 SQL 中,我正在尝试这样的事情:

SomeName.value('declare namespace p1="http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDigest";(p1:AppMgmtDigest/p1:DeploymentType)[1]', 'nvarchar(max)') as Test

现在由于某种原因这有效:

someVar.value('declare namespace p1="http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDigest";(p1:AppMgmtDigest/p1:Application/p1:AutoInstall)[1]', 'nvarchar(max)') = 'true'

为什么需要填充那些 p1 声明?对不起,我是新手

XQuery
.

xml powershell xquery
© www.soinside.com 2019 - 2024. All rights reserved.