how to fetch child nodes of parent node in XML .. using c#...
-
hello every one... I am tried to retrieve a node FieldsToSupport/FieldToSuport in a xml.. Following is the structure of my xml file.....there can be multiple into in a . Also can be multiple.. ------------------------------------------------------------ 0 1.0.1 e7dfee93-14f0-4775-baef-c7246dfae902 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\iframeCopy.html Updating Adding New Row 3 Blank Blank NewField1 15b85c2b-83ca-44ec-8741-22a4dc64f64d http://careers.msn.com/ Careers & Jobs <A href="http://careers.msn.com">Careers & Jobs</A> Blank Blank Screen2 97d5c477-a5f4-4496-8084-19a537d85e29 http://slate.com/ Slate Magazine <A href="http://slate.com">Slate Magazine</A> label3 172.0934 ------------------------------------------------------------ and following is my code in c#. I am try to fetch node
-
hello every one... I am tried to retrieve a node FieldsToSupport/FieldToSuport in a xml.. Following is the structure of my xml file.....there can be multiple into in a . Also can be multiple.. ------------------------------------------------------------ 0 1.0.1 e7dfee93-14f0-4775-baef-c7246dfae902 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\iframeCopy.html Updating Adding New Row 3 Blank Blank NewField1 15b85c2b-83ca-44ec-8741-22a4dc64f64d http://careers.msn.com/ Careers & Jobs <A href="http://careers.msn.com">Careers & Jobs</A> Blank Blank Screen2 97d5c477-a5f4-4496-8084-19a537d85e29 http://slate.com/ Slate Magazine <A href="http://slate.com">Slate Magazine</A> label3 172.0934 ------------------------------------------------------------ and following is my code in c#. I am try to fetch node
Well I have some suggestions for you. First I recommend, it's what I use, www.w3schools.com as an excellent reference for things like XPath etc. Second, find yourself a method of testing XPath statements before you try to integrate them into code. I mean you just type a statement and execute it in some environment to see that you obtain the node or node set desired. There might be something you can get for free and it's not that difficult to write a little command line utility or even a Windows Forms application for testing XPath statements. Lastly, when you want to create a paramaterized XPath statement don't use string concatination, use String.Format(...) with format strings that have placeholders for the parameters. It's far simpler to get the XPath statement syntax correct when you do that. Let's use your statement as an example:
"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='"+strScreenId+"']";
The format string would be:"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='{0}']";
then use it in String.Format and pass the parameter to fill in the placeholder. Now to your problem. You XPath statement syntax is incorrect, there should be no path separator before the expressionScreenToSupport/[ScreenUniqueId
should beScreenToSupport[ScreenUniqueId
-
Well I have some suggestions for you. First I recommend, it's what I use, www.w3schools.com as an excellent reference for things like XPath etc. Second, find yourself a method of testing XPath statements before you try to integrate them into code. I mean you just type a statement and execute it in some environment to see that you obtain the node or node set desired. There might be something you can get for free and it's not that difficult to write a little command line utility or even a Windows Forms application for testing XPath statements. Lastly, when you want to create a paramaterized XPath statement don't use string concatination, use String.Format(...) with format strings that have placeholders for the parameters. It's far simpler to get the XPath statement syntax correct when you do that. Let's use your statement as an example:
"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='"+strScreenId+"']";
The format string would be:"/LinkInformation/ScreensToSupport/ScreenToSupport/[ScreenUniqueId='{0}']";
then use it in String.Format and pass the parameter to fill in the placeholder. Now to your problem. You XPath statement syntax is incorrect, there should be no path separator before the expressionScreenToSupport/[ScreenUniqueId
should beScreenToSupport[ScreenUniqueId
hello sir the way you tried to explain me is excellent.. But I am did'nt get you point 'then use it in String.Format and pass the parameter to fill in the placeholder.' How we pass parameter into String.Format pls tell m? Thanks a lot
-
hello sir the way you tried to explain me is excellent.. But I am did'nt get you point 'then use it in String.Format and pass the parameter to fill in the placeholder.' How we pass parameter into String.Format pls tell m? Thanks a lot