mahesh kumar B M

mahesh kumar B M

  • NA
  • 44
  • 1.1m

to get child elements OF AN XML USING C#,LINQ ,XML

Feb 25 2014 1:14 PM
I have the xml structure like this..
<TABLE NAME="PDF " PRIMARYKEYE="PDF ">   <FIELD NAME="PNUMBER" FIELD="FieldTypeNumber" />   <FIELD NAME="STATUS" FIELDTYPE="FieldTypeNumber" />   <FIELD NAME="COMPANY" FIELDTYPE="FieldTypeNumber" /> <FORM NAME="PDF_DOC" TITLE="REGEN_PDF_DOC">   <FORMFIELD NAME="POLICY_NUMBER" DBCOLUMNNAME="(SLECT POLICY_NUMBER FROM POLICY ,NOTE WHERE POLICY.POLICY=NOTE.TABLE_KEY)" />   <FORMFIELD NAME="STATUS" DBCOLUMNNAME="(SELECT STATUS FROM STATUS_VALUE)" />   <FORMFIELD NAME="COMPANY" DBCOLUMNNAME="(SELECT COMPANY FROM COMPANY WHERE COMPANY=20000)" />   <FORMFIELD NAME="ENTERPRISE" />   <FORMFIELD NAME="EFFECTIVE_DATE" /> </FORM> <SEARCH NAME="SEARCHPDF" ORDERBYCLAUSE="PDF ">   <JOIN TABLE="NOTATION" TYPE="LEFT" ON="PDF  CONDITION="ISNOTNULL" />   <JOIN TABLE="PNUM" TYPE="INNER" ON="NOTE= POLICY" CONDITION="ISNOTNULL" />   <SEARCHFIELD NAME="PNUMBER" LABEL="PNUMBER" />   <SEARCHFIELD NAME="EFFECTIVE_DATE" LABEL="EFFECTIVE DATE" /> </SEARCH>   </TABLE>

Im trying to list out the elements with the name "JOIN" using the below syntax.but ending up with null values..can somebody fix this?

The source file "filename.xml" is loaded as xdocument and i ahve used LINQ to achioeve this using XELEMENT.


XElement table = this.filename.Root.Elements("TABLE").Single(W => W.Attribute("NAME").Value.Equals("PDF "));
 
Now im trying to list out the elements with the element nae as JOIN with the below syntax;
 
IEnumerable joins = table.Element("SEARCH").Elements("JOIN");
 
but even after execution , the variable joins still has null value instead of 2 join elements . Can someone look into this?




Answers (1)