List Info

Thread: C-Sharp (C#) Group: Parsing class doc




C-Sharp (C#) Group: Parsing class doc
user name
2006-05-05 17:30:13
Hello, I'm given this XML document that contains a People
class that
consist of teachers, students and TA's and I wanted to
build up a
classes list of the information provided by that document to
list out
the teachers, all its students and TA's that is associated
with the
same classes.

//////Example input:

<People>
	<Person>
           <First> M</First>
            <Last> Burns </Last>
            <Handle> MBurns </Handle>
            <Teach> biology </Teach>
            <Teach> chemistry </Teach>
       </Person>
       <Person>
           <First> Lista </First>
           <Last> Simpson </Last>
           <Handle> Lsimpson </Handle>
           <TA> biology </TA>
           <Student> history </Student>
           <Student> english </Student>
       </Person>
       <Person>
          <First> Homer </First>
          <Last> Simpson </Last>
          <Handle> HSimposon </Handle>
          <Student> writing </Student>
          <Student> biology </Student>
          <Student> art </Student>
       </Person>
</People>

/////Example Output:

<Classes>
	<Class>
		<Name>biology</Name>
		<Teach>MBurns</Teach>
		<TA>Lsimpson</TA>
		<Student>HSimposon</Student>
	</Class>
</Classes


I believe there is an XML reader built int C# ? I wasn't
sure how to
start the parsing process. Thank you


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Parsing class doc
user name
2006-05-05 21:08:02
There is lots and lots and lots of Xml Functionality built in to .net, choose the right one is the hard part. Given you are looking to transform the data XSLT is the best choice. There lots and lots of examples floating around for doing XSL transforms in .net and is does vary depending on which version of the framework. Take a look at MSDN to see some example code but if you run in to trouble feel free to give me a shout. Anyway where is the XSL which gives you the desired output:

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
<xsl:stylesheet version=&quot;1.0&quot; xmlnssl="http://www.w3.org/1999/XSL/Transform ";>
 ; <xsl:output method=&quot;xml";/>

&nbsp; <xsl:template match=&quot;/People&quot;>
&nbsp; &nbsp; <Classes>
 ; &nbsp; &nbsp; <xsl:apply-templates select=&quot;Person/Teach"/>
   ; </Classes>
&nbsp; </xsl:template>

  <xsl:template match=&quot;Person/Teach"&gt;
 &nbsp;  <xsl:variable name=";ClassName&quot; select=&quot;." />
&nbsp; &nbsp; <Class&gt;
 &nbsp;   ; <Name&gt;<xsl:value-of select=&quot;$ClassName" /></Name>
&nbsp;   ;  <Teach&gt;<xsl:value-of select=&quot;../Handle"/>;</Teach>
   ; &nbsp; <TA><xsl:value-of select=&quot;/People/Person[TA = $ClassName]/Handle&quot;/><;/TA>
&nbsp; &nbsp;   <xsl:apply-templates select=&quot;/People/Person/Student[text() = $ClassName]" />
&nbsp; &nbsp; </Class>
  </xsl:template>

  <xsl:template match=&quot;Person/Student">
   ; <Student><xsl:value-of select=&quot;../Handle"/>;</Student>
&nbsp; </xsl:template>
 
</xsl:stylesheet&gt;

This gives the following output from your sample data:


&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
  <Classes>
 ; &nbsp; <Class&gt;
 &nbsp;   ; <Name&gt; biology </Name&gt;
   ; &nbsp; <Teach&gt; MBurns </Teach>
   ; &nbsp; <TA> Lsimpson </TA>;
 &nbsp; &nbsp;  <Student> HSimposon </Student>
&nbsp; &nbsp; </Class>
   ;
 &nbsp;  <Class&gt;
 &nbsp;   ; <Name&gt; chemistry </Name&gt;
   ; &nbsp; <Teach&gt; MBurns </Teach>
   ; &nbsp; <TA></TA>
 &nbsp;  </Class>
  </Classes>

Liam


On 5/5/06, tyjunior <gmail.com">cppisfungmail.com> wrote:

Hello, I'm given this XML document that contains a People class that
consist of teachers, students and TA's and I wanted to build up a
classes list of the information provided by that document to list out
the teachers, all its students and TA's that is associated with the
same classes.

//////Example input:

&lt;People>;
 &nbsp; &nbsp; &nbsp;  <Person>
&nbsp;   ; &nbsp; &nbsp; &nbsp; <First&gt; M</First>
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ;<Last&gt; Burns </Last&gt;
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &lt;Handle&gt; MBurns </Handle>
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;<Teach> biology </Teach>
   ; &nbsp; &nbsp; &nbsp; &nbsp; <Teach&gt; chemistry </Teach>
   ; &nbsp;  </Person>
 ; &nbsp; &nbsp;  <Person>
   ; &nbsp; &nbsp; &nbsp;  <First&gt; Lista </First>
   ; &nbsp; &nbsp; &nbsp;  <Last&gt; Simpson </Last&gt;
   ; &nbsp; &nbsp; &nbsp;  <Handle> Lsimpson </Handle>
 ; &nbsp; &nbsp; &nbsp; &nbsp;  <TA> biology </TA>;
 &nbsp; &nbsp; &nbsp;   ;  <Student> history </Student>
&nbsp; &nbsp; &nbsp; &nbsp;   ; <Student> english </Student>
&nbsp; &nbsp; &nbsp;  </Person>
&nbsp; &nbsp; &nbsp;  <Person>
   ; &nbsp; &nbsp; &nbsp; &lt;First>; Homer </First>
   ; &nbsp; &nbsp; &nbsp; &lt;Last> Simpson </Last&gt;
 &nbsp;   ; &nbsp; &nbsp; &lt;Handle>; HSimposon </Handle>
 ; &nbsp; &nbsp; &nbsp; &nbsp; <Student> writing </Student>
&nbsp; &nbsp; &nbsp;   ; &nbsp;<Student> biology </Student>
&nbsp; &nbsp; &nbsp; &nbsp;   ;<Student> art </Student>
&nbsp; &nbsp; &nbsp;  </Person>
</People>

/////Example Output:

&lt;Classes&gt;
 &nbsp;   ; &nbsp; <;Class>
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &lt;Name>biology</Name>
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  <Teach>MBurns</Teach>
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;<TA&gt;Lsimpson</TA>
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &lt;Student&gt;HSimposon</Student>
 ; &nbsp; &nbsp; &nbsp; &lt;/Class&gt;
</Classes


I believe there is an XML reader built int C# ? I wasn't sure how to
start the parsing process. Thank you




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Parsing class doc
user name
2006-05-06 18:52:54
The code that your provided is XLST right? It's not the C#
program that
would parse the XML document right? I think afterwards I
would like an
XLST that would take the output generated by C# and turn it
into a
nicely formatted HTML document. I'm still trying to start
on the
parsing using C#.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Parsing class doc
user name
2006-05-06 23:51:52
That XSL will parse the XML and output the desired XML structure. If you want to do it entirely in c# you want the XmlTextReader or XPathDocument class (stay clear of XmlDocument, there is no better way of destroying application performance then using it).

In terms of the XmlTextReader class it is forward only (which means you can't use XPath to query it) and will not validate the XML structure. Coding with it is somewhat like coding with recordsets in classic asp in that you you extract some data, move next and loop until you reach end of file. Obviously because it is multi-dimensional data the story is a little more complicated then that. Basicly your logic would go something like:

XmlTextReader xtr = Load the Xml

while(xtr.Read())
{

}

On 5/6/06, tyjunior <gmail.com">cppisfungmail.com > wrote:

The code that your provided is XLST right? It's not the C# program that
would parse the XML document right? I think afterwards I would like an
XLST that would take the output generated by C# and turn it into a
nicely formatted HTML document. I'm still trying to start on the
parsing using C#.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Parsing class doc
user name
2006-05-07 00:03:24
Whoops, hit reply a little too early there. The quasi code you want is:

XmlTextReader xtr = Load the Xml

NameValueCollection PeopleOnClasses;

NameValueCollection PeopleTeachingClasses;

NameValueCollection TAForClasses;

string strHandle;

while(xtr.Read())
{
  ; &nbsp; if NodeType = "element"
   &nbsp; {
 &nbsp; &nbsp; &nbsp;    &nbsp; &nbsp; &nbsp; switch (NodeName)
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; case "handle"
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; strHandle = NodeValue

 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; case "teach"
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  PeopleTeachingClasses.Add(NodeValue, strHandle)

 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  ...

 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; }
 &nbsp; &nbsp; }
}

That would be the kind of thing you want to do and then use an XmltextReader to output some Xml data based on the collections. There is a pretty good video tutorial for the XTR class over at http://www.xmlforasp.net/CodeSection.aspx?csID=114


Liam

On 5/7/06, Liam Leane <gmail.com">greapygmail.com > wrote:
That XSL will parse the XML and output the desired XML structure. If you want to do it entirely in c# you want the XmlTextReader or XPathDocument class (stay clear of XmlDocument, there is no better way of destroying application performance then using it).

In terms of the XmlTextReader class it is forward only (which means you can't use XPath to query it) and will not validate the XML structure. Coding with it is somewhat like coding with recordsets in classic asp in that you you extract some data, move next and loop until you reach end of file. Obviously because it is multi-dimensional data the story is a little more complicated then that. Basicly your logic would go something like:

XmlTextReader xtr = Load the Xml

while(xtr.Read())
{


}

On 5/6/06, tyjunior <gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">cppisfungmail.com > wrote:

The code that your provided is XLST right? It's not the C# program that
would parse the XML document right? I think afterwards I would like an
XLST that would take the output generated by C# and turn it into a
nicely formatted HTML document. I'm still trying to start on the
parsing using C#.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Parsing class doc
user name
2006-05-07 23:12:59
I tried that tutorial that you gave me and they used html
output with
links and I was trying to follow along but I got stuck at
some places
and was wondering if you can take a look at what I have and
maybe
clarify some things if I'm doing it incorrectly.

[code]
using System;
using System.XML;
using System.Text;

//reads XML document from command line arg[1]
XmlTextReader xtr = Load the Xml;

//var to keep track of People In Classes
NameValueCollection PeopleOnClasses;

//var to keep track of People teaching classes
NameValueCollection PeopleTeachingClasses;

//var to keep track of people TA classes
NameValueCollection TAForClasses;

//string handler
string strHandle;

//skip white space and move to content
xtr.MoveToContent();

//call read func to start reading
while(xtr.Read())
{
	//checks for people tag and also is a root node
	if(xtr.Name == "People" && xtr.NodeType
== XmlNodeType.Element)
	{
		//retrieve the name of the course
		if(xtr.Name == "Person")
		{
			strHandle = xtr.ReadString();
		}
		//person name that is teaching course
		if(xtr.Name == "Handle")
		{
			PeopleTeachingClasses = xtr.ReadString();
		}
		//whos teaching course
		if(xtr.Name == "Teach")
		{
			PeopleTeachingClasses.Add(NodeValue, strHandle);
		}
		if(xtr.Name == "TA")
		{

		}
		if(xtr.Name == "Student")
		{

		}
		//check for ending tag
		if(xtr.Name == "People" &&
xtr.NodeType == XmlNodeType.EndElement)
		{

		}
	}
	//output the data
}
        	//closes the stream
	xtr.Close();
[/code]

Specifically, I wans't sure how to add the sub-tags to the
main tag of
a "Person", as you can see I know that you just
have to find the root
node which is "Person" and then traverse in and
continue addign the
sub-tags to the main root, once you find an ending tag of
"Person" you
would then output the data and continue to the next, once
you're done
with that you would want to close up the stream.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Parsing class doc
user name
2006-05-08 00:08:06
Ok first thing I would suggest is have a think about the way an XmlReader based class works. The important bit of information in its description is "Forward only". This means that you can't go back and look to see what a value was previously in the tree so checking if a node is inside another node has to be addressed in another way. I have knocked together some code that will fill up the NVCs with the correct values for you below. One of the interesting problems that are faced when attempting to use an XmlReader is this way is when you have an identifier (in this case the Handle) is an element rather then an attribute because we can't go backwards to process values. If your Handle tag will always appear before the teach, ta & student tags then this model will work fine. If it wont you need to use a unique indeifier for your person before they are known (such as a guid) and then go back and modify the nvc when they are known.

Just as a warning I don't have time to test this code out this evening but it compiles fine and in theory should work fine too, would be happy to debug it tommorow if it doesnt work, just let me know.

using System;
using System.Collections.Specialized;
using System.IO;
using System.Xml;

namespace Demo
{
&nbsp; &nbsp; public class Demo
 ; &nbsp; {
 &nbsp; &nbsp;   ; //var to keep track of People In Classes
&nbsp; &nbsp;   ;  private NameValueCollection f_nvcPeopleOnClasses = new NameValueCollection();

 &nbsp;   ; &nbsp; //var to keep track of People teaching classes
&nbsp; &nbsp;   ;  private NameValueCollection f_nvcPeopleTeachingClasses = new NameValueCollection();

 &nbsp; &nbsp;   ; //var to keep track of people TA classes
&nbsp; &nbsp;   ;  private NameValueCollection f_nvcTAForClasses = new NameValueCollection();
 &nbsp; &nbsp;   ;
 &nbsp; &nbsp; &nbsp;  public void ProcessXmlInput(string Xml)
 ; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; XmlTextReader xtrReader = new XmlTextReader(new StringReader(Xml));

  ; &nbsp; &nbsp; &nbsp; &nbsp;  //skip white space and move to content
&nbsp;   ; &nbsp; &nbsp; &nbsp;  xtrReader.MoveToContent();

&nbsp; &nbsp; &nbsp; &nbsp;   ;  while(xtrReader.Read())
 &nbsp; &nbsp;   ; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; if(xtrReader.NodeType == XmlNodeType.Element && xtrReader.Name.ToLower() == "person")
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  //We now know we are inside a person node
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ProcessPerson(xtrReader);
   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  }
 &nbsp; &nbsp;   ; &nbsp; &nbsp; }
 &nbsp; &nbsp;   ; }

 &nbsp;   ; &nbsp; private void ProcessPerson(XmlTextReader PersonReader)
   ; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; string strHandle = string.Empty;

   ; &nbsp; &nbsp; &nbsp; &nbsp; //At this point we know that we are at the begining of a
 &nbsp; &nbsp; &nbsp;   ; &nbsp; // person tag so want to loop the XML until we reach the end of it
   ; &nbsp; &nbsp; &nbsp; &nbsp; while(PersonReader.Name.ToLower() != "person")
&nbsp;   ; &nbsp; &nbsp; &nbsp;  {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; if(PersonReader.NodeType != XmlNodeType.EndElement)
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  switch(PersonReader.Name.ToLower ())
   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  case "handle":
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  strHandle = PersonReader.Value;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  break;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; case "teach":
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  CheckAndAddToCollection(f_nvcPeopleTeachingClasses, strHandle, PersonReader.Value);
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;  break;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; case "ta&quot;:
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; CheckAndAddToCollection(f_nvcTAForClasses, strHandle, PersonReader.Value);
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  break;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; case "student":
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;  CheckAndAddToCollection(f_nvcPeopleOnClasses, strHandle, PersonReader.Value);
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  break;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; }
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; }

 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   PersonReader.Read();
  ; &nbsp; &nbsp; &nbsp; &nbsp;  }
 &nbsp; &nbsp;   ; }
 &nbsp; &nbsp;   ;
 &nbsp; &nbsp; &nbsp;  private void CheckAndAddToCollection(NameValueCollection Collection, string Handle, string Value)
&nbsp; &nbsp;   ;  {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; if(Handle == null || (Handle != null && Handle.Length == 0))
   ; &nbsp; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; throw new ArgumentNullException("Handle", "Handle may not be null. Handle node occuring after other nodes?&quot;);
 ; &nbsp; &nbsp; &nbsp; &nbsp;   }

 &nbsp;   ; &nbsp; &nbsp; &nbsp; //It would be a valid condition to hhave an empty node so cope with it
 &nbsp;   ; &nbsp; &nbsp; &nbsp; if(Value != null && Value.Length > 0)
 &nbsp;   ; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; //Check if thhe user is already in the list
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  if(Collection[Handle] != null && Collection[Handle].Length > 0)
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  //User is so add the item
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  Collection[Handle] += string.Format ("|", Value);
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  }
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; else
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;  {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  //User is not so create a new entry
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  Collection.Add(Handle, Value);
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  }
 &nbsp;   ; &nbsp; &nbsp; &nbsp; }
 &nbsp; &nbsp;   ; }
 &nbsp;  }
}

Liam

On 5/8/06, tyjunior <gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> cppisfungmail.com > wrote:

I tried that tutorial that you gave me and they used html output with
links and I was trying to follow along but I got stuck at some places
and was wondering if you can take a look at what I have and maybe
clarify some things if I'm doing it incorrectly.

[code]
using System;
using System.XML;
using System.Text;

//reads XML document from command line arg[1]
XmlTextReader xtr = Load the Xml;

//var to keep track of People In Classes
NameValueCollection PeopleOnClasses;

//var to keep track of People teaching classes
NameValueCollection PeopleTeachingClasses;

//var to keep track of people TA classes
NameValueCollection TAForClasses;

//string handler
string strHandle;

//skip white space and move to content
xtr.MoveToContent();

//call read func to start reading
while(xtr.Read())
{
&nbsp; &nbsp; &nbsp; &nbsp; //checks for people tag and also is a root node
 ; &nbsp; &nbsp; &nbsp; if(xtr.Name == "People" && xtr.NodeType == XmlNodeType.Element)
  ; &nbsp; &nbsp; &nbsp;{
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;//retrieve the name of the course
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;if(xtr.Name == "Person")
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; {
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; strHandle = xtr.ReadString ();
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; }
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; //person name that is teaching course
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;if(xtr.Name == "Handle")
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; {
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; PeopleTeachingClasses = xtr.ReadString ();
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; }
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; //whos teaching course
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;if(xtr.Name == "Teach")
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  {
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; PeopleTeachingClasses.Add(NodeValue, strHandle);
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;}
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;if(xtr.Name == "TA&quot;)
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;{

 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;}
   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;if(xtr.Name == "Student")
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; {

  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; }
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; //check for ending tag
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;if(xtr.Name == "People" && xtr.NodeType == XmlNodeType.EndElement)
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; {

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; }
 &nbsp; &nbsp; &nbsp;  }
&nbsp; &nbsp; &nbsp;   ;//output the data
}
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;//closes the stream
&nbsp; &nbsp;   ; &nbsp;xtr.Close();
[/code]

Specifically, I wans't sure how to add the sub-tags to the main tag of
a "Person", as you can see I know that you just have to find the root
node which is "Person" and then traverse in and continue addign the
sub-tags to the main root, once you find an ending tag of "Person" you
would then output the data and continue to the next, once you're done
with that you would want to close up the stream.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )