How to extract value from element xml if other element has a especific value

For example. I want to extract values from n4:AdditionalProperty

if n2:Name == “@@FamiliaProducto” then value=“Recaudaciones y Pagos”

but I want to use this sintaxis

“xmlDes.Root.Descendants(dicNamespaces(“n4”) + “AdditionalProperty”).Elements(dicNamespaces(“n2”) + “Value”)(1).Value.ToString”

is it possible?

 <ext:UBLExtensions>
    <n3:UBLExtension xmlns:n3="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:n0="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:n1="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:n2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:n4="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:prx="urn:sap.com:proxy:F4P:/1SAI/TAS07A0A4A524DF9674494B:754">
      <n3:ExtensionContent>
        <n4:AdditionalInformation>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Name>@@FamiliaProducto</n2:Name>
            <n2:Value>Recaudaciones y Pagos</n2:Value>
          </n4:AdditionalProperty>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Name>@@TipoPrestamo</n2:Name>
            <n2:Value>Servicios Especiales por Consulta. Credipago</n2:Value>
          </n4:AdditionalProperty>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Name>@@NumeroContrato</n2:Name>
            <n2:Value>191 ****079 * **</n2:Value>
          </n4:AdditionalProperty>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Name>@@FechaPago</n2:Name>
            <n2:Value>2022-11-11</n2:Value>
          </n4:AdditionalProperty>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Name>@@CodFamiliaProducto</n2:Name>
            <n2:Value>RP</n2:Value>
          </n4:AdditionalProperty>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Name>@@CodAplicativo</n2:Name>
            <n2:Value>CREP</n2:Value>
          </n4:AdditionalProperty>
          <n4:AdditionalProperty>
            <n2:ID />
            <n2:Value />
          </n4:AdditionalProperty>
        </n4:AdditionalInformation>
      </n3:ExtensionContent>
    </n3:UBLExtension>
    <ext:UBLExtension>

What functions or method I should use to get the value with some conditions?

Maybe the following will work or provide complete XML data for cross checks

xmlDes.Root.Descendants(dicNamespaces(“n4”) + "AdditionalProperty").Where(Function (x) x.Element(dicNamespaces("n2") + "Name").Value.Trim.Equals("@@FamiliaProducto")).Select(Function (x) x.Element(dicNamespaces("n2") + "Value").Value).FirstOrDefault()

But with Query Syntax we can organize it more readable used within an assign activity

strValue =
(From xe In xmlDes.Root.Descendants(dicNamespaces("n4") + "AdditionalProperty")
Where xe.Element(dicNamespaces("n2") + "Name").Value.Trim.Equals("@@FamiliaProducto")
Select v=  xe.Element(dicNamespaces("n2") + "Value").Value).FirstOrDefault()

Also good to know is to using XPath with a Namespacemanager, when xPath is known and filter predicates can be managed

1 Like

May we ask you to Close the topic by marking the solving Post as solution or let us know your further Open question on this. Thanks

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