Utilizziamo già
Un'opzione potrebbe essere parse the output into C# code e quindi codificarlo in XML, facendo in modo che ogni nodo in string.Format("<{0}>", this.Name);
e nel mezzo inserisca ricorsivamente tutti i nodi figlio.
Dopo aver eseguito questa operazione, utilizzare a tool for querying XML/HTML per analizzare l'albero. Migliaia di persone usano già i selettori di query e jQuery per analizzare la struttura ad albero in base alla relazione tra i nodi. Penso che questo sia di gran lunga superiore a TRegex o ad altre utilità java obsolete e non mantenute.
Ad esempio, questo è per rispondere alla tua primo esempio:
var xml = CQ.Create(d.ToXml());
//this can be simpler with CSS selectors but I chose Linq since you'll probably find it easier
//Find joe, in our case the node that has the text 'Joe'
var joe = xml["*"].First(x => x.InnerHTML.Equals("Joe"));
//Find the last (deepest) element that answers the critiria that it has "Joe" in it, and has a VBD in it
//in our case the VP
var closestToVbd = xml["*"].Last(x => x.Cq().Has(joe).Has("VBD").Any());
Console.WriteLine("Closest node to VPD:\n " +closestToVbd.OuterHTML);
//If we want the VBD itself we can just find the VBD in that element
Console.WriteLine("\n\n VBD itself is " + closestToVbd.Cq().Find("VBD")[0].OuterHTML);
Ecco il vostro secondo esempio
//Now for NP closest to 'Shopping', find the element with the text 'shopping' and find it's closest NP
var closest = xml["*"].First(x => x.InnerHTML.Equals("shopping")).Cq()
.Closest("NP")[0].OuterHTML;
Console.WriteLine("\n\n NP closest to shopping is: " + closest);
fonte
2013-02-04 12:22:52
Per downvoter, ti dispiacerebbe spiegare perché? Questa domanda si riferisce chiaramente alle FAQ del sito. –