SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: XML help

  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    XML help

    Hey all,

    How would I go about using C# to read an XML document? I've had a quick look in the docs but there's so many objects that I got sort of lost. I have a document like this
    Code:
    <!DOCTYPE log SYSTEM "log.dtd">
    
    <log>
    
    	<entry>
    	
    		<date>22 August 2003</date>
    		
    		<text>
    			This is a sample log entry.
    		</text>
    	
    	</entry>
    	
    </log>
    And I want the app I'm writing to be able to read that file, and create a temp static HTML file to open in a browser. I can't imagine something like this would be too difficult, but as I said, I just can't figure out where to start.

    Thanks

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Thanks for the links, but my C# app will be a Windows app, not ASP.NET, and that isn't really what I'm looking for (I don't think).

    My idea is that XML is another form of data storage, so what I'd like to do is load the XML file into an object or something, and then be able to do something like this (pseudocode)
    Code:
    string strOutput = null;
    XmlObject log = new XmlObject('log.xml');
    foreach ( XmlEntity entry in log.Etity["entry"] ) {
    	strOutput += "<tr>
    			<td>
    			  <b>"+ent.date.name.ToString()+"</b>: "+ent.date.value.ToString()"<br /><br />
    			  "+ent.text.value.ToString()+"
    			</td>
    		      </tr>";
    }
    If you know what I mean? Just turn all the XML entities into objects and format some HTML to save to a temp file and then open. If you think there is a better way to do this however, let me know. Note there will be no server software on the client machine and ASP.NET is a no go

    Thanks

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Sep 2002
    Location
    Cleveland, Ohio, USA
    Posts
    1,494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't matter if it's a Windows app, ASP.Net app or a console app. The links Chuckie posted have examples that apply all the same.


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
  •