SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to read XMl file using Xpath

    Hi all,
    I have to read a XML using Xpath in Visual Studio .Net 1.1 using c#.
    But couldn't do it.
    Can anyone help me.?
    i am stuck with my code.
    The XMl file is as follows:
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
     <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
     <ERRORCODE>0</ERRORCODE> 
     <PRODUCT BUILD="02-10-2004" NAME="AutoSpec2" VERSION="7.0v1" /> 
     <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="AutoSpec2d.USR" RECORDS="4" TIMEFORMAT="h:mm:ss a" /> 
     <METADATA>
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="File_Name" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Description" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Purpose" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Parent" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Type" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Classification" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Status" TYPE="TEXT" /> 
     <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Category" TYPE="TEXT" /> 
     
     </METADATA>
     <RESULTSET FOUND="4">
     <ROW MODID="7" RECORDID="1498">
     <COL>
     <DATA>P1_U02_C01_001P_RD10</DATA> 
     </COL>
     <COL>
     <DATA>Size:Full Students painting fence</DATA> 
     </COL>
     <COL>
     <DATA>To show teamwork</DATA> 
     </COL>
     <COL>
     <DATA>Parent code need to be mentioned here</DATA> 
     </COL>
     <COL>
     <DATA>Spec type (Art or Photo)</DATA> 
     </COL>
     <COL>
     <DATA>Classification should mentioned here( for example "New", "PU","2ndU" etc) </DATA> 
     </COL>
     <COL>
     <DATA>Status need to mention here (for ex : Created, Release,Approved etc)</DATA> 
     </COL>
     <COL>
     <DATA>category (For example "RESEARCH","TECH" etc)</DATA> 
     </COL>
     </ROW>
     </RESULTSET>
     </FMPXMLRESULT>
    Please help me.
    -::Ujjwal::-
    Visit My Site

  2. #2
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.
    I have writen it.
    my code is as follows:
    Code:
    /******* Working on XML Reading ********/
    
    					XPathDocument doc = new XPathDocument(Server.MapPath("~/Uploaded_File/" + fileName));
    					XPathNavigator nav = doc.CreateNavigator();	
    					XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
    					nsmgr.AddNamespace("S", "http://www.filemaker.com/fmpxmlresult");
    
    					XPathExpression expr = nav.Compile("S:FMPXMLRESULT//S:ROW");
    					expr.SetContext(nsmgr);
    					XPathNodeIterator rows = nav.Select(expr);
    
    					XPathExpression exprIn = nav.Compile("//S:COL");
    					exprIn.SetContext(nsmgr);
    					while (rows.MoveNext())
    					{
    						XPathNodeIterator cols = rows.Current.Select(exprIn);
    						string MODID = rows.Current.GetAttribute("MODID", "");	
    						XPathExpression exprFinal = nav.Compile("S:DATA");
    						exprFinal.SetContext(nsmgr);
    						while (cols.MoveNext())
    						{	
    									string DATA =GetInnerXml(cols.Current.Select(exprFinal).Current);
    						} 					             
    					}
    -::Ujjwal::-
    Visit My Site

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    I would suggest using XDocument and Linq 2 XML. It will save you a lot of time in the future

  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NightStalker-DNS View Post
    I would suggest using XDocument and Linq 2 XML. It will save you a lot of time in the future
    I must agree. Linq adds another color to the rainbow. Linq clones unicorns. Linq makes the word "incurable" passť.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •