Getting attribute value from xml using xpath to get file path

I have the following xml file:
<?xml version="1.0" encoding="utf-8" ?> 
<course id="2555" title="Developing Microsoft .NET Applications for Windows 
(Visual C# .NET)" length="5 days" 
source="http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx">
	<module id="1" title="Introducing Windows Forms" 
location="D:\Disk-C\Documents and Settings\orit_itzhar.ATRICA\My 
Documents\XML\csharp">
		<lesson id="1.1">
			<subject>Creating a Form</subject>
			<file>Introducing_Windows_Forms_Course-2555-Module-1.pdf</file>
		</lesson>
		<lesson id="1.2">
			<subject>Adding Controls to a Form</subject>
			<file>type&exceptions.pdf</file>
		</lesson>
		<lesson id="1.3">
			<subject>Creating an Inherited Form</subject>
			<file>winforms.pdf</file>
		</lesson>
		<lesson id="1.4">
			<subject>Organizing Controls on a Form</subject>
			<file>BnsLrnCs.zip</file>
		</lesson>
		<lesson id="1.5">
			<subject>Creating MDI Applications</subject>
			<file>Working_with_Controls_Course-2555-Module-2.pdf</file>
		</lesson>
		<lab id="1.1">
			<exercise id="1.1.1">Creating a New Windows Form</exercise>
			<exercise id="1.1.2">Inheriting a New Form from an Existing Windows 
Form</exercise>
		</lab>
	</module>
		<module id="2" title="Working with Controls" location="D:\Disk-C\Documents 
and Settings\orit_itzhar.ATRICA\My Documents\XML\c#">
		<lesson id="2.1">
			<subject>Creating an Event Handler for a Control</subject>
			<file>Introducing_Windows_Forms_Course-2555-Module-1.pdf</file>
		</lesson>
		<lesson id="2.2">
			<subject>Using Windows Forms Controls</subject>
			<file>type&exceptions.pdf</file>
		</lesson>
		<lesson id="2.3">
			<subject>Using Dialog Boxes in a Windows Forms Application</subject>
			<file>winforms.pdf</file>
		</lesson>
		<lesson id="2.4">
			<subject>Adding Controls at Run Time</subject>
			<file>BnsLrnCs.zip</file>
		</lesson>
		<lesson id="2.5">
			<subject>Creating Menus</subject>
			<file>Working_with_Controls_Course-2555-Module-2.pdf</file>
		</lesson>
		<lesson id="2.6">
			<subject>Validating User Input</subject>
			<file>Working_with_Controls_Course-2555-Module-2.pdf</file>
		</lesson>
		<lab id="2.1">
			<exercise id="2.1.1">Creating and Using Controls</exercise>
		</lab>
	</module>
</course>

I want to get the path to file by getting the "location" attribute from the 
"module" node, and concatenating the inner text of the "file" to it.
I tried the code below to get out the location into the courseDocumentsPath 
varaiable:
			XmlDocument doc = new XmlDocument();
			doc.LoadXml("lessons.xml");

				string courseDocumentsPath = null;

				XmlNodeList nl = doc.SelectNodes("/course/module/@location");
				foreach(XmlNode node in nl)
				{
					courseDocumentsPath = node.Value;
				}

I get on this System error, Can someone please help what is the problem?

Thanks
0
Orit (9)
9/7/2005 3:28:07 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
596 Views

Similar Articles

[PageSpeed] 45

XmlDocument.LoadXml() loads a XML String, so it assumes that the 
argument you pass in is valid XML, as in:

        doc.LoadXml("<test>xyz</test>");

You want to use XmlDocument.Load(), which allows you to pass in a path:

        doc.Load("Lessons.xml")

HTH,

Bennie Haelen

orit wrote:
> I have the following xml file:
> <?xml version="1.0" encoding="utf-8" ?> 
> <course id="2555" title="Developing Microsoft .NET Applications for Windows 
> (Visual C# .NET)" length="5 days" 
> source="http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx">
> 	<module id="1" title="Introducing Windows Forms" 
> location="D:\Disk-C\Documents and Settings\orit_itzhar.ATRICA\My 
> Documents\XML\csharp">
> 		<lesson id="1.1">
> 			<subject>Creating a Form</subject>
> 			<file>Introducing_Windows_Forms_Course-2555-Module-1.pdf</file>
> 		</lesson>
> 		<lesson id="1.2">
> 			<subject>Adding Controls to a Form</subject>
> 			<file>type&exceptions.pdf</file>
> 		</lesson>
> 		<lesson id="1.3">
> 			<subject>Creating an Inherited Form</subject>
> 			<file>winforms.pdf</file>
> 		</lesson>
> 		<lesson id="1.4">
> 			<subject>Organizing Controls on a Form</subject>
> 			<file>BnsLrnCs.zip</file>
> 		</lesson>
> 		<lesson id="1.5">
> 			<subject>Creating MDI Applications</subject>
> 			<file>Working_with_Controls_Course-2555-Module-2.pdf</file>
> 		</lesson>
> 		<lab id="1.1">
> 			<exercise id="1.1.1">Creating a New Windows Form</exercise>
> 			<exercise id="1.1.2">Inheriting a New Form from an Existing Windows 
> Form</exercise>
> 		</lab>
> 	</module>
> 		<module id="2" title="Working with Controls" location="D:\Disk-C\Documents 
> and Settings\orit_itzhar.ATRICA\My Documents\XML\c#">
> 		<lesson id="2.1">
> 			<subject>Creating an Event Handler for a Control</subject>
> 			<file>Introducing_Windows_Forms_Course-2555-Module-1.pdf</file>
> 		</lesson>
> 		<lesson id="2.2">
> 			<subject>Using Windows Forms Controls</subject>
> 			<file>type&exceptions.pdf</file>
> 		</lesson>
> 		<lesson id="2.3">
> 			<subject>Using Dialog Boxes in a Windows Forms Application</subject>
> 			<file>winforms.pdf</file>
> 		</lesson>
> 		<lesson id="2.4">
> 			<subject>Adding Controls at Run Time</subject>
> 			<file>BnsLrnCs.zip</file>
> 		</lesson>
> 		<lesson id="2.5">
> 			<subject>Creating Menus</subject>
> 			<file>Working_with_Controls_Course-2555-Module-2.pdf</file>
> 		</lesson>
> 		<lesson id="2.6">
> 			<subject>Validating User Input</subject>
> 			<file>Working_with_Controls_Course-2555-Module-2.pdf</file>
> 		</lesson>
> 		<lab id="2.1">
> 			<exercise id="2.1.1">Creating and Using Controls</exercise>
> 		</lab>
> 	</module>
> </course>
> 
> I want to get the path to file by getting the "location" attribute from the 
> "module" node, and concatenating the inner text of the "file" to it.
> I tried the code below to get out the location into the courseDocumentsPath 
> varaiable:
> 			XmlDocument doc = new XmlDocument();
> 			doc.LoadXml("lessons.xml");
> 
> 				string courseDocumentsPath = null;
> 
> 				XmlNodeList nl = doc.SelectNodes("/course/module/@location");
> 				foreach(XmlNode node in nl)
> 				{
> 					courseDocumentsPath = node.Value;
> 				}
> 
> I get on this System error, Can someone please help what is the problem?
> 
> Thanks
0
9/7/2005 7:12:40 PM
Reply:

Similar Artilces:

Text Values
Hello, Can anybody help, I'm after making a spreadsheet in Excel to record times for individuals, for example if I typed in 'early shift' with the value of 10 hours, after 'noon shift' 8 hours as well as 'late' shift at 12 hours...etc, the total values would all show in a totals cell for that person. I would appreciate any help with the above. Love, Susan ***** Posted via: http://www.ozgrid.com Excel Templates, Training & Add-ins. Free Excel Forum http://www.ozgrid.com/forum ***** Hi Susan one way: use a helper column which transforms this text string int...

How to repair a .dll file in IE8
Several days ago I noticed in my Dependency Walker that the IESHIMS.dll files has a yellow circle with a question mark on it. What does this mean and How do I repair it? OS: Windows Vista Home Premium Browser Internet Explorer 8 -- TW Hi, See the History tab on that dialog. A web search for ieshims.dll files will also help you find a solution for that file. Regards. "TW" <TW@discussions.microsoft.com> wrote in message news:63E61463-D766-4ABC-B081-BFA8C04FB159@microsoft.com... > Several days ago I noticed in my Dependency Walker that the IESHIMS....

Using Relative path for XML data file?
Is there a way to specify a relative path to an XML data file imported into Excel 2003? I am writing a web app that generates report data as XML for the user to download to their local machine. This data is to be consumed by an Excel reporting spreadsheet, which contains display-formatted tables and charts that are mapped to various data fields in an XML Map, which is in turn linked to the xml data file they will download. The idea is the user only needs to download the data for updates, not the whole spreadsheet. However, since I cannot predict the path where the user will store their...

unsolicited entry in the folder "Temporary Internet Files"
Hello, I am working on a programme which browses web sites and runs under XP. The http download is as follows: pServer = Isession -> GetHttpConnection(strServerName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags); pFile->SendRequest(); pFile->QueryInfoStatusCode(dwStatusCode); if(dwStatusCode == 200) { pFile -> QueryInfo(HTTP_QUERY_LAST_MODIFIED, &sysT); status.lastMod = sysT; if(DBlastMod == status.lastMod) //URL content has not changed since the last visit ...

Linking files 2 ways
I have a work book that is linked to another and vise versa. As thus: Workbook A is where the input of data is made; Workbook B has a link to the input from workbook A; Workbook A retrieves the altered data back as a link. Although this all works fine with both books open, I note that if I open workbook A by itself, that the data it retrieves from Workbook B is not updated . If However, both books are open, there's no problem. I thought linked books were updated automatically if the Update remote references has been selected?? But it appears that the second book is not updated until it ...

OL2007 not move big files from outbox to sent
Hi, We have 2 computers with separate email accounts on Roadrunner. One machine has XP with Outlook 2002-sp3 and works without any problems. The other has Outlook 2007 on Vista and has problems sending files over a meg or so in size. It seems to actually send the file but the file remains in the outbox folder and does not move it to the sent folder. I say it "seems" to send the file because some people complain of getting muliple copies and others don't seem to get them at all. If I hit send again (not set up for auto send) it seems to send the file again (why some ...

Formula without using numbers after decimal in the answer
I have a formula that derives the answer from a figure with a decimal. I don't want to use the figures after the decimal. Is there a way to just use the whole number and omit the numbers after the decimal without having to manually key in all these numbers manually? Thanks, Mustang You can use the INT function. This 'rounds down' any number to th nearest integer, e.g. if A1=2.567, a formula in B2 of =INT(A1) return 2 HTH Bruc -- swatsp0 ----------------------------------------------------------------------- swatsp0p's Profile: http://www.excelforum.com/member.php?...

how to convert lookup values to the "display text"
I'm using an sql code (below) which uses a few lookup fields. Unfortunately in the datasheet view, I get the "bound values" instead of the "display values". How can I change the properties for the these lookup fields so I can see the "display values" from the datasheet view? SELECT [Funding],[Date],[Description],[Company],[Expense_Type],[Amount],[Status] FROM [Form_9_Status] UNION ALL SELECT [Funding],[Date],[Description],[Company],[Expense_Type],[Amount],[Status] FROM [TDY_Status] UNION ALL SELECT [Funding],[Date],[Description],[C...

find action on log file
Hello there I want to use outside tool to find who made some update on table in my server I know that there are many tools for this. But can they do it on simple recovery model? Roy Goldhammer (royg@yahoo.com) writes: > I want to use outside tool to find who made some update on table in my > server > > I know that there are many tools for this. But can they do it on simple > recovery model? No. If you are using the simple recovery model, the contents of the log is wasted away everyonce in a while. Well, if the disk area has not been overwritten...

File size #11
I have read the other discussions on file sizes but they do not seem to address my problem. I have an Excel file that is 12mb large with low-res jpegs in it. This file also has merged cells to make it look pretty. Does Excel look at these merged cells as graphics? Is this why they are too big? I have run a macro to make sure that it goes to the last cell. How can I get the file smaller? How big are the graphics? If you remove them from the file, what is the size of the file and what is the size of the graphic files? To be sure you do not have extra formatting, if you open the file...

Maximum file sizes
Is there a recommended maximum file size for Excel 2000. PC spec 2Ghz P4 with 256 Mb Any advice appreciated Deus -------------- Does Not Exist Hi have a look at http://www.decisionmodels.com/memlimits.htm -- Regards Frank Kabel Frankfurt, Germany "Deus DNE" <deus.dne@ntlworld.com> schrieb im Newsbeitrag news:1561701c41d4f$358950f0$a001280a@phx.gbl... > Is there a recommended maximum file size for Excel 2000. > > PC spec 2Ghz P4 with 256 Mb > > Any advice appreciated > > Deus > -------------- > Does Not Exist ...

POST or GET?
(apologies if this is OT but I couldn't find an HTTP newsgroup) I am writing an MFC client application which speaks to an HTTP server. The server will send text data to the client, the client will modify and return that data to the server along with a small amount of new data. Should I use GET or POST to get the data from the server? "Richard" <richard@hello.com> wrote in message news:zWudf.14758$Cq4.8824@newsfe7-gui.ntli.net... > I am writing an MFC client application which speaks to an HTTP server. The > server will send text data to the client, the client...

How to delete a set of rows depending on Value
I have two worksheets Worksheet A 27 Columns 1600 Rows. Worksheet B 1 Column 200 Rows I need Worksheet A to look at each cell in Worksheet B, if a cell exists in Worksheet A, then I need the row deleted... Basically I have a list of Grand list of items to do, then a list of items already completed. I need to now remove all entries in the grand list that have been completed. Is this feasible or should I look at using some Unix script. It sounds like you could use VLOOKUP to find out if the value in B exists on A: http://www.officearticles.com/excel/vlookup_formulas_in_microsoft_excel....

'top' is not a valid value for the 'vertical-align' property.
Well, it is, actually, and the resulting .chm file works properly in HTML Help. But it's a bit tedious getting that wrong useless error message from VS2002 on every build. (Well, not every build, it only does it sometimes actually.) Any idea how I can persuade it to stop telling me this? -- Tim Ward Brett Ward Limited - www.brettward.co.uk ...

Cannot open Outlook, keep getting Send error report of Microsoft.
We are having problems with Outlook 2003. Everytime we try to open, we get this: Send error report to Microsoft. Any ideas why? All windows and office update have been completed. ...

CSV Files and VLOOKUP error
Does anyone know why VLOOKUP and Compare formulas don't work o information originating from a CSV file? I've tried copying an pasting values only (to leave behind any formatting), but it doesn' help. Through countless tests, I've narrowed it down to the CSV file bein the only possible cause -- Message posted from http://www.ExcelForum.com Hi ajpowers, Just a guess but the imported data may have leading or trailing spaces or are numbers stored as text. You could use the formula =A1=D1 to see if you get a true or false, where A1 is the lookup value and D1 ia the CVS valu...

using the journal on outlook
Once I link an email to the journal, can I still find that email in my mail box? I seem to be able to get to it only via the journal. If this is the way it is supposed to be, how do I remove it from the journal and get it back into my mail box? Am I just missing something? -- thanks, Independent Are you linking to the item or putting a copy into the journal item? Also, has the item been archived or not? "Independent" <Independent@discussions.microsoft.com> wrote in message news:868279F2-53C8-403A-97F5-604CEECD873C@microsoft.com... > Once I link an email to the journ...

default values in a cell
Hello, can you help me please Cell B1 contains a complex mathematical formula which requires (in several places) a number from cell A1. Cell A1 can contain any integer number, but it is usually the same (30). I would like to be able to leave cell A1 empty, and only enter a number when it is not 30 , ie the default value of A1 is 30, unless specified. How do I go about this ? Should I look at conditional formatting, or put lots of IF functions into an already complex formula? Thank as always KK Use 2 cells Modify the complex formula to use B1 rather than A1 ( or any other un-u...

Disable Secure Sockets Layer on exchange server when using RPC over HTTP
Hi im trying to enable RPC over HTTP to enable users to establish contact to my Excahger server 2003 over the internet. Now, I dont want to use SSL (security not that important) and i am told by this article that i can disable SSL in windows registry. Quote: Note While RPC over HTTP does not require Secure Sockets Layer, you must modify the registry to enable RPC over HTTP if you do not want to use Secure Sockets Layer. Microsoft recommends that you enable and require Secure Sockets Layer for your RPC over HTTP communications. At this address: http://support.microsoft.com/?id=833401 But i ...

How to automate increasing the form cache registry/file etc...
I want to roll out a batch file to make a number of tweaks to CRM The body of it would go REGEDIT /S Kerberosefix.reg REGEDIT /S ForceFormreload.reg REGEDIT /S OutlookFix.reg It would also rename OSA.exe to OSA.bad Remove OSA.exe From the startup menu I need help finding a way to use my batch file to increase the Outlook Form cache from the default 4MB to 50 MB.. This makes CRm more stable and faster for communications. I dont want to manually do this, as it time consuming, are my end users would not be reliable in doing it themselves. I also want to make another batch file or button that...

get a result of an sql into a field
Hi there I would like to get a result of an sql execution (ms sql server) into aq filed. example i A1 I have a ID number in A2 I would like to get the result of something like this 'select name from address where id=A1' Does this exist in Excel ? Thanks in advance Ralf Here is the sub i have written for loading an Sql Query into th worksheet. Parameters: Server Name DataBase Name SQL Command Target Sheet name Column to begin from Row to begin from ex: CALL LoadData("MyServer","MyDataBase","Select UserName fro TblNames", "QueryData"...

Average of absolute values of moving ranges
I'm trying to get the average of the absolute values of a set of data over 8 weeks. Each week is on a seaparate sheet so to capture the moving ranges I've been using the formula below to get my result. Is there an easier way? =AVERAGE(ABS('Week 1'!G2-'Week 2'!G2),ABS('Week 2'!G2-'Week 3'!G2),ABS('Week 3'!G2-'Week 4'!G2),ABS('Week 4'!G2-'Week 5'!G2),ABS('Week 5'!G2-'Week 6'!G2),ABS('Week 6'!G2-'Week 7'!G2),ABS('Week 7'!G2-'Week 8'!G2)) Thanks! Amy The use of t...

How do you invoke the Let and Get class Functions
I have create classes with the Let and Get functions and now I would like to use these functions to store and retrieve data in the class which will then be put into a collection. Here is the class functions: Private pBusPart As Double Private pStartTime As Date Private pIndex As Integer '''''''''''''''''''''' ' BusPart property '''''''''''''''''''''' Public Property Get BusPart() As Double BusPar...

I cannot get Outlook to send/receive. Error says object not found
I just installed Outlook2007. I cannot get the send/receive to work. That is when the error says Object not found. If I go to accounts and properties, I run the two tests and they complete fine. What should I try next? Outlook 2007 is the only new program, all the rest are from Office 2003 IMK <IMK@discussions.microsoft.com> wrote: > I just installed Outlook2007. I cannot get the send/receive to work. > That is when the error says Object not found. If I go to accounts and > properties, I run the two tests and they complete fine. What should I > try next? Outlook 2007 is ...

How to get to email from Word
Sorry to break the thread, but replying to the original thread now produces an error message :( The suggested changes don't make any difference to the essential premise that it all works as long as Outlook is running in the background. Stepping though the code has provided inconsistent results. It usually crashes at the line strEMail = Application.GetAddress("", strEMail, False, 1, , , True, True) when the address is selected from the dialog and you OK out of the dialog; but I have noticed that this call has produced crashes in other routines where Outlook is not running. Th...