I have an XML like below:
<TRANSFORMATION DESCRIPTION ="" NAME ="RTR_LRC_RF_REFL_Unproc" OBJECTVERSION ="1" REUSABLE ="NO" TYPE ="Router" VERSIONNUMBER ="1">
<GROUP DESCRIPTION ="" NAME ="INPUT" ORDER ="1" TYPE ="INPUT"/>
<GROUP DESCRIPTION ="" EXPRESSION ="EXP 1" NAME ="Good" ORDER ="2" TYPE ="OUTPUT"/>
<GROUP DESCRIPTION ="Path for the data when none of the group conditions are satisfied." NAME ="DEFAULT1" ORDER ="3" TYPE ="OUTPUT/DEFAULT"/>
<TRANSFORMFIELD DATATYPE ="integer" DEFAULTVALUE ="" DESCRIPTION ="" GROUP ="INPUT" NAME ="OWNER_HEORG_REFNO" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="10" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="integer" DEFAULTVALUE ="" DESCRIPTION ="" GROUP ="INPUT" NAME ="PATNT_REFNO" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="10" SCALE ="0"/>
<TRANSFORMFIELD DATATYPE ="integer" DEFAULTVALUE ="" DESCRIPTION ="" GROUP ="INPUT" NAME ="REFRL_REFNO" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="10" SCALE ="0"/>
==============================================================================================
<GROUP DESCRIPTION ="" EXPRESSION ="(Valid_Record_Flag = 'Y'
<GROUP DESCRIPTION ="Path for the data when none of the group condition
<GROUP DESCRIPTION ="" EXPRESSION ="EXP2" .../>
<GROUP DESCRIPTION ="" EXPRESSION ="EXP3" .../>
<GROUP DESCRIPTION ="" EXPRESSION ="EXP4" .../>
I use C# (LINQ to XML) to get some info from the abocve XML.
In the above XML, you can see the node under . You can also see that the EXPRESSION attribute for GROUP node occuring only once. I also have other sets of nodes, where they also contain nodes, but they have multiple EXPRESSION attributes (the nodes below the ===== divider).
My requirement is, I want to extract some info from GROUP Nodes having EXPRESSION attribute occuring only once.
I currently use the following C# code to extract the info:
var q = from c in xmlDoc.Descendants("TRANSFORMATION")
where c.HasAttributes &&
c.Attribute("TYPE") != null && !String.IsNullOrEmpty(c.Attribute("TYPE").Value) &&
c.Attribute("TYPE").Value.ToUpper().Equals("ROUTER")
select c.Descendants("TRANSFORMFIELD");
But this gives all TRANSFORMFIELD nodes including GROUP nodes having EXPRESSION attribute occuring only once.
How do I get TRANSFORMFIELD nodes where GROUP nodes having EXPRESSION attribute occuring more than once?
Many thanks!
I’m not 100% sure I understand your requirements but I think you only want to get all
TRANSFORMFIELDof theTRANSFORMATIONthat contains more than oneGROUPelement that has anEXPRESSIONdefined. You could do this: