473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Parse XML Backwards

I have the following XML File: I want to parse the file so that I can add each node to a database: So I need to parse the bottom node and say:
admissions, application. Then go up a level and extract "the admissions application"


<Token Type="TOP" Dectiption="" >
<Token Type="SBARQ" Dectiption="" >
<Token Type="WHNP" Dectiption="" >
<Token Type="WP" Dectiption="wh-pronoun" >What</Token>
</Token>
<Token Type="S" Dectiption="" >
<Token Type="VP" Dectiption="Verb Phrase" >
<Token Type="VBP" Dectiption="Verb, non-3rd ps. sing. present" >are</Token>
<Token Type="NP" Dectiption="Noun Phrase">
<Token Type="NP" Dectiption="Noun Phrase">
<Token Type="DT" Dectiption="Determiner" >the</Token>
<Token Type="NNS" Dectiption="Noun, plural" >fees</Token>
</Token>
<Token Type="PP" Dectiption="Prepositional Phrase">
<Token Type="IN" Dectiption="Preposition/subordinate" >for</Token>
<Token Type="NP" Dectiption="Noun Phrase" >
<Token Type="DT" Dectiption="Determiner">the</Token>
<Token Type="NNS" Dectiption="Noun, plural">admissions</Token>
<Token Type="NN" Dectiption="Noun, singular or mass">application</Token>
</Token>
</Token>
</Token>
</Token>
</Token>
</Token>
</Token>
Mar 5 '08 #1
1 1578
You should use some kind of recursive function, like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public string ProcessXML(XmlNode node)
  3.         {            
  4.             if (node.ChildNodes.Count == 0)
  5.             {
  6.                 return node.InnerText;
  7.             }
  8.             else
  9.             {
  10.                 StringBuilder sentence = new StringBuilder();
  11.                 for (int i = 1; i < node.ChildNodes.Count; i++)
  12.                 {
  13.                     sentence.Append(ProcessXML(node));
  14.                 }
  15.                 return sentence.ToString();
  16.             }
  17.         }
  18.  
  19.  
  20.  
  21.  
*****note: I haven't tested this, it's just an example/pseudocode
Mar 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Chris | last post by:
Can anybody help. I need to read a txt file backwords line by line. Can anybody help me do this. Thanks Chris
1
by: Jason Mobarak | last post by:
Greetings! Say that it's desirable to provide backwards compatibility for methods of an object, consider the case where... class Foo: def bar (self, a, b): pass ....is a defined class...
0
by: flat_ross | last post by:
If there was one thing nice about "Binary Compatibility" in VB6, it would tell you at compile time that you changed your public interface. I am looking for the same functionality in .NET. I know...
15
by: SK | last post by:
Hey folks, I am searching for a string (say "ABC") backwards in a file. First I seek to the end. Then I try to make a check like - do { file.clear (); file.get(c); file.seekg(-2,...
10
by: Russell Mangel | last post by:
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore>...
6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
70
by: py | last post by:
I have function which takes an argument. My code needs that argument to be an iterable (something i can loop over)...so I dont care if its a list, tuple, etc. So I need a way to make sure that...
2
by: PJ6 | last post by:
I can probably code this up manually myself but I'd prefer to use a built-in method that I'm sure exists... I have a message box client-side control (thanks, Steve Orr) that uses the JavaScript...
8
by: Rico | last post by:
Hello Everyone, I observed something strange in some quick testing code: void Button1Click(object sender, System.EventArgs e) { CultureInfo culture = new CultureInfo("th-TH", false); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.