Getting XML attribute

Hi Guys, I have the following response but am having difficulty retrieving the data I need to.

Here is the response:

<s:Envelope xmlns:s=“http://schemas.xmlsoap.org/soap/envelope/”>

<s:Header>

    <XXX-CorrelationId xmlns="XXX">XXX-17a2089487f1</***-CorrelationId>

    <BGT-CorrelationSource xmlns="XXX">XXX-&gt;GetParameterValuesForKeyAndGroupListFull</XXX>

</s:Header>

<s:Body>

    <GetParameterValuesForKeyAndGroupListFullResponse xmlns="XXX">

        <GetParameterValuesForKeyAndGroupListFullResult xmlns:a="XXXX" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

    
            <Session xmlns="http://schemas.datacontract.org/2004/07/XXX_Globals_Objects">

                <AdditionalInfos i:nil="true" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>

                <SessionId>13185903</SessionId>

                <SessionNodeId>218845</SessionNodeId>

                <SessionPartnerId>XXX</SessionPartnerId>

                <StatusCode>0</StatusCode>

                <StatusMessage i:nil="true"/>

            </Session>

            <StatusCode xmlns="XXX/2004/07/XXX_Globals_Objects">0</StatusCode>

            <StatusMessage xmlns="XXX2004/07/BGT_Globals_Objects">ST_GEN_OK</StatusMessage>

            <Timestamp xmlns="X/2004/07/BGT_Globals_ObjectsXX">2020-10-13T10:30:46.5952933+02:00</Timestamp>

            <a:Parameter xmlns:b="hXXX2003/10/Serialization/Arrays">

                <b:KeyValueOflongArrayOfKeyValueOfstringParameterWithValuesTODgLEScIUty7Ep6D1>

                    <b:Key>10</b:Key>

                    <b:Value>

                        <b:KeyValueOfstringParameterWithValuesTODgLEScIU>

                            <b:Key>node.password</b:Key>

                            <b:Value xmlns:c="http://schemas.datacontract.org/2004/07/XXX_Objects.TransferObjects">

                                <c:HasCustomValues>true</c:HasCustomValues>

                                <c:ParameterDefinition>

                                    <c:Annotation>Password required for login</c:Annotation>

                                    <c:AnnotationDictionaryEntriesNr>1818671</c:AnnotationDictionaryEntriesNr>

                                    <c:DefaultValue>Password</c:DefaultValue>

                                    <c:DefaultValueDictionaryEntriesNr>1816487</c:DefaultValueDictionaryEntriesNr>

                                    <c:EncryptionTypesNr>1</c:EncryptionTypesNr>

                                    <c:Inherits>false</c:Inherits>

                                    <c:Key>node.password</c:Key>

                                    <c:MaxCacheTimeMs>10000</c:MaxCacheTimeMs>

                                    <c:MultipleValuesAllowed>false</c:MultipleValuesAllowed>

                                    <c:ParameterDefinitionsId>*1*</c:ParameterDefinitionsId>

This Response is resulting in just Two Nodes - the first one is the Header one, then the larger second one is Body (Goes on for much longer)

I am unable to get the element for Example in the last line, the “1” value.

Could someone advise on how to get the value for c:ParameterDefinitionsId in the last line for example?

Much appreciated!

Hi,

Hope the following sample helps you.

Sample20201013-1.zip (15.2 KB)

Regards,

2 Likes

@Kyleb91
as your XML is dealing with naespace @Yoichi has provided the demo handling this.

Find an approach on how to handle with config / mapping tables and doing the retrieval with the help of XPath:

1 Like

Thank you so much @Yoichi brilliant stuff. A bit for me to digest.

Could I ask a favour of how you would similarly use this string to find a value, where there are multiple instances of the original "xmlns:c and subsequent ParameterValuesId values…

sample.txt (11.7 KB)

I am trying to retrieve the specific value “100810866”. Not sure how I should be accessing the Key “<b:Key>node.failedLogins.number</b:Key>”

Much Appreciated!

Thanks a lot @ppr I shall look into this now!

Hi,

The above your sample is not valid as xml. (eg. lack definition of b)
Can you share original xml as a file?

Regards,

sample.xml (21.5 KB)

Apologies, see attached. I need to get the value “100810866”, and I can get it with your solution but also all of the other values with the same Namespace and Descendants…

Thanks in advance!

Hi,

Can you try the following sample?

Sample20201013-1v2.zip (5.1 KB)

Regards,

1 Like

Fantastic @Yoichi much appreciated! I couldn’t get this myself! Thanks again!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.