odelacruz
(Oscar Elias De La Cruz Cotrina)
December 5, 2022, 3:34pm
1
How to validate if a element exist or is empty.
Sometimes, the element @@FechaPago is empty or simply, the element is not found in the xml, so I want to check if the element exists with name==@@FechaPago and value is not empty then it extracts the value and fecha_pago==“05-12-2022” else my variable fecha_pago==“N/A”
<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-28</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>
ppr
(Peter Preuss)
December 5, 2022, 3:49pm
2
Similar to
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") + "AdditionalPr…
give a try:
(From xe In xmlDes.Root.Descendants(dicNamespaces("n4") + "AdditionalProperty")
Where xe.Element(dicNamespaces("n2") + "Name").Value.Trim.Equals("@@FechaPago")
Select v= xe.Element(dicNamespaces("n2") + "Value").Value).DefaultIfEmpty("N/A").First()
odelacruz
(Oscar Elias De La Cruz Cotrina)
December 6, 2022, 2:17pm
3
@ppr good morning, i want only validate if the elemento @@FechaPago exist, and the activity return 0 if don’t exist, 1 if exist.
ppr
(Peter Preuss)
December 6, 2022, 2:20pm
4
hasFound | Boolean =
(From xe In xmlDes.Root.Descendants(dicNamespaces("n4") + "AdditionalProperty")
Where xe.Element(dicNamespaces("n2") + "Name").Value.Trim.Equals("@@FechaPago")
Select e= xe).Any
will return true if one or more @@FechaPago exists
ppr
(Peter Preuss)
December 6, 2022, 2:51pm
6
ensure within the debugging / panels that xmlDes is of Datatype XDocument and not null
similar to the dicNamespaces are to check that it is correct
Maybe you can also share the XML file with us
odelacruz
(Oscar Elias De La Cruz Cotrina)
December 6, 2022, 3:50pm
7
Your statement work when the elemento name==@@fechaPago exist, but when name==@@fechaPago doesn’t exist in xml I get the message of error.
odelacruz
(Oscar Elias De La Cruz Cotrina)
December 6, 2022, 4:01pm
8
BCP_des.xml (22.3 KB)
In this example the element with value"@@fecha de Pago" doesn’t exist.
ppr
(Peter Preuss)
December 6, 2022, 4:10pm
9
Based on this example we would recommend first to check if the ni namespace is within the dictionary:
dicNameSpaces.ContainsKey("n2")
When it is within the name space then we can go ahead.
Maybe you can also share a complete sample XML with existing n2 Elements, so we can evaluate the statement.
system
(system)
Closed
December 9, 2022, 4:11pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.