XPath for groups of related elements?
XPath for groups of related elements?
I am trying to get the information <l7:Name>
and corresponding all <l7:IssuerName>
<l7:Name>
<l7:IssuerName>
<?xml version="1.0" encoding="UTF-8"?>
<l7:List xmlns:l7="http://ns.l7tech.com/2010/04/gateway-management">
<l7:Item>
<l7:Name>services.company.int</l7:Name>
<l7:Id>00000000000000000000000000000004:-services.company.int</l7:Id>
<l7:Type>SSG_KEY_ENTRY</l7:Type>
<l7:TimeStamp>2018-08-28T10:25:04.615-05:00</l7:TimeStamp>
<l7:Link rel="self" uri="https://10.154.244.13:443/restman/1.0/privateKeys/00000000000000000000000000000004:-services.company.int"/>
<l7:Resource>
<l7:PrivateKey alias="-services.company.int" keystoreId="00000000000000000000000000000004" id="00000000000000000000000000000004:-services.company.int">
<l7:CertificateChain>
<l7:CertificateData>
<l7:IssuerName>CN=MC Access Management sub CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
<l7:SerialNumber>83060681499471284401614700485002472352</l7:SerialNumber>
<l7:SubjectName>DC=net,DC=company,O=company WorldWide - CentralAuth,OU=xmlgw-auth-client,CN=services.company.int</l7:SubjectName>
</l7:CertificateData>
<l7:CertificateData>
<l7:IssuerName>CN=Access Management root CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
</l7:CertificateData>
<l7:CertificateData>
<l7:IssuerName>CN=Access Management root CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
</l7:CertificateData>
</l7:CertificateChain>
<l7:Properties>
<l7:Property key="keyAlgorithm">
<l7:StringValue>RSA</l7:StringValue>
</l7:Property>
</l7:Properties>
</l7:PrivateKey>
</l7:Resource>
</l7:Item>
<l7:Item>
<l7:Name>directory-company-com</l7:Name>
<l7:Id>00000000000000000000000000000004:--directory-company-com</l7:Id>
<l7:Type>SSG_KEY_ENTRY</l7:Type>
<l7:TimeStamp>2018-08-28T10:25:04.615-05:00</l7:TimeStamp>
<l7:Resource>
<l7:PrivateKey alias="--directory-company-com" keystoreId="00000000000000000000000000000004" id="00000000000000000000000000000004:--directory-company-com">
<l7:CertificateChain>
<l7:CertificateData>
<l7:IssuerName>CN=PRD company 3DS1 Issuer Sub CA,OU=company Identity Check Gen 3,O=company,C=US</l7:IssuerName>
<l7:SubjectName>CN=.directory.company.com,OU=gateway-signing,O=company Worldwide,C=US</l7:SubjectName>
</l7:CertificateData>
<l7:CertificateData>
<l7:IssuerName>CN=PRD company Identity Check Root CA,OU=company Identity Check Gen 3,O=company,C=US</l7:IssuerName>
<l7:SerialNumber>231453887433606512122984068379445229638</l7:SerialNumber>
<l7:SubjectName>CN=PRD company 3DS1 Issuer Sub CA,OU=company Identity Check Gen 3,O=company,C=US</l7:SubjectName>
</l7:CertificateData>
<l7:CertificateData>
<l7:IssuerName>CN=PRD company Identity Check Root CA,OU=company Identity Check Gen 3,O=company,C=US</l7:IssuerName>
<l7:SubjectName>CN=PRD company Identity Check Root CA,OU=company Identity Check Gen 3,O=company,C=US</l7:SubjectName>
</l7:CertificateData>
</l7:CertificateChain>
<l7:Properties>
<l7:Property key="keyAlgorithm">
<l7:StringValue>RSA</l7:StringValue>
</l7:Property>
</l7:Properties>
</l7:PrivateKey>
</l7:Resource>
</l7:Item>
</l7:List>
I have tried this /l7:List/l7:Item/l7:Resource/l7:PrivateKey/l7:CertificateChain/l7:CertificateData/l7:IssuerName
and /l7:List/l7:Item/l7:Name
.
/l7:List/l7:Item/l7:Resource/l7:PrivateKey/l7:CertificateChain/l7:CertificateData/l7:IssuerName
/l7:List/l7:Item/l7:Name
I am struggling to correlate both.
Any advise would be helpful.
expecting output
<l7:Name>services.company.int</l7:Name>
<l7:IssuerName>CN=MC Access Management sub CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
<l7:IssuerName>CN=Access Management root CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
//l7:Name
//*[local-name()="Name"]
//*[local-name()="Name"] does gives all the names. but I am for Name and corresponding IssuerName between Resource
– Kumar_y
Aug 28 at 21:53
And
//l7:Name
selects nothing?– kjhughes
Aug 28 at 21:55
//l7:Name
It also gives same output. List of all the l7:Name
– Kumar_y
Aug 28 at 22:19
Ok, so that establishes that it's not a namespace issue. And I see you've added the expected output. Good progress. Keep in mind that XPath selects. If you want to transform or rearrange that which you've selected, you'll need to step up to XSLT.
– kjhughes
Aug 28 at 23:03
2 Answers
2
This XPath,
/l7:List/l7:Item//*[self::l7:Name or self::l7:IssuerName]
will select
<l7:Name>services.company.int</l7:Name>
<l7:IssuerName>CN=MC Access Management sub CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
<l7:IssuerName>CN=Access Management root CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
<l7:IssuerName>CN=Access Management root CA,OU=Global Information Security,O=company WorldWide,DC=company,DC=net</l7:IssuerName>
<l7:Name>directory-company-com</l7:Name>
<l7:IssuerName>CN=PRD company 3DS1 Issuer Sub CA,OU=company Identity Check Gen 3,O=company,C=US</l7:IssuerName>
<l7:IssuerName>CN=PRD company Identity Check Root CA,OU=company Identity Check Gen 3,O=company,C=US</l7:IssuerName>
<l7:IssuerName>CN=PRD company Identity Check Root CA,OU=company Identity Check Gen 3,O=company,C=US</l7:IssuerName>
which, I believe, satisfies your request for
the information <l7:Name>
and corresponding all <l7:IssuerName>
<l7:Name>
<l7:IssuerName>
That's not an attribute, that's a namespace. Look up xpath & namespaces.
Here is a quick code to atleast find "l7:issuername":
//*[name()='l7:issuername']
which finds 6, throw them into an array and do what you want with them.
Good luck!
As kjhughes stated or you can do this.
//*[name()='l7:IssuerName' or name()='l7:Name']
Thanks for sending the Xpath but I am able to get that individually. However was wondering it was possible to let the list all Names and IssueName
– Kumar_y
Aug 28 at 22:40
Testing
name()
for equality with some string is poor practice because namespace prefixes are unpredictable. Rather than [name()='xxxxx']
, always write [self::xxxxx]
(at least, if you're testing elements - attributes are a bit different).– Michael Kay
Aug 28 at 23:33
name()
[name()='xxxxx']
[self::xxxxx]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Does
//l7:Name
select nothing while//*[local-name()="Name"]
selects something?– kjhughes
Aug 28 at 21:13