Question

Searched and tried all examples here but no luck. I want to find the value of node 'CustomID' from this XML:

<?xml version="1.0" encoding="UTF-8"?>
<AppMgmtDigest xmlns="http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDigest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Application AuthoringScopeId="ScopeId_B831987C-E9E7-47D5-95A5-1EEAC7B035D5" LogicalName="Application_d030d07c-a5ef-419b-aa46-44ff0697050b" Version="13">
        <DisplayInfo DefaultLanguage="en-US">
            <Info Language="en-US">
                <Title>Adobe Acrobat Professional XI</Title>
                <Publisher>Adobe</Publisher>
                <Version>11.0.00</Version>
                <Tags>
                    <Tag>Adobe Acrobat Professional XI</Tag>
                </Tags>
            </Info>
        </DisplayInfo>
        <DeploymentTypes>
            <DeploymentType AuthoringScopeId="ScopeId_B831987C-E9E7-47D5-95A5-1EEAC7B035D5" LogicalName="DeploymentType_9193d006-04f2-41e5-8495-62bedf3f79e4" Version="10" />
        </DeploymentTypes>
        <Title ResourceId="Res_814073674">Adobe Acrobat Professional XI</Title>
        <Description ResourceId="Res_469365393" />
        <Publisher ResourceId="Res_231516204">Adobe</Publisher>
        <SoftwareVersion ResourceId="Res_266572543">11.0.00</SoftwareVersion>
        <CustomId ResourceId="Res_1915338015">**THIS IS ANSWER**</CustomId>
        <AutoInstall>true</AutoInstall>
        <Owners>
            <User Qualifier="LogonName" Id="abc" />
        </Owners>
        <Contacts>
            <User Qualifier="LogonName" Id="abc" />
        </Contacts>
        <HighPriority>1</HighPriority>
        <AutoDistribute>true</AutoDistribute>
    </Application>
</AppMgmtDigest>

The value (of node ) I want is "THIS IS ANSWER". I tried this but no luck:

select a.b.value('.','varchar(max)')
    from @xml.nodes('//AppMgmtDigest/Application/CustomId') a(b);
Was it helpful?

Solution

Your XML has a namespace which you need to consider in your XPath expression.

You can extract the text you want without taking the namespace into account using this XPath expression:

//*[local-name()='AppMgmtDigest']/*[local-name()='Application']/*[local-name()='CustomId'] 

You can try:

select a.b.value('.','varchar(max)') 
    from @xml.nodes('//*[local-name()="AppMgmtDigest"]/*[local-name()="Application"]/*[local-name()="CustomId"]') a(b);

You can also register the namespace. You would probably have to add something like this before your select query:

;with xmlnamespaces ('http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDige‌​st' as prefix)

Where prefix is any prefix you want. Then you use the prefix to qualify the XPath elements:

//prefix:AppMgmtDigest/prefix:Application/prefix:CustomId
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top