lettura nodo

  • Thread starter Thread starter T-Mat
  • Start date Start date
T

T-Mat

<?xml version="1.0" encoding="utf-8"?>
<TRACCIATI>
<TRACCIATO>
<TABLE NAME="01">
<FIELD NAME="uno" START="0" LEN="5" />
<FIELD NAME="due" START="5" LEN="6" />
<FIELD NAME="tre" START="11" LEN="8" />
<FIELD NAME="quattro" START="13" LEN="10" />
<FIELD NAME="cinque" START="23" LEN="2" />
</TABLE>
<TABLE NAME="10">
<FIELD NAME="sei" START="1" LEN="6" />
<FIELD NAME="sette" START="6" LEN="7" />
<FIELD NAME="otto" START="12" LEN="9" />
<FIELD NAME="nove" START="14" LEN="11" />
<FIELD NAME="dieci" START="24" LEN="3" />
</TABLE>
</TRACCIATO>
</TRACCIATI>

In linguaggio C#
CIao io ho questo file XML come faccio a far visualizzare sulla console
solo il contenuto della tabella01?!

E come faccio a visualizzare sulla console soltanto il campo della
tabella10 con NAME=sette?!

grazie x chi mi darà na mano...
 
I didn't understand the first part of your question. For the second, XQuery
is the easiest option:

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlElement el =
(XmlElement)doc.SelectSingleNode("/TRACCIATI/TRACCIATO/TABLE[@NAME='10']/FIELD[@NAME='sette']");
Console.WriteLine("Start: " + el.GetAttribute("START"));
Console.WriteLine("Len: " + el.GetAttribute("LEN"));

Does this help at all? If you clarify the first part of your question I may
be able to help more, but I didn't understand what babelfish
(http://babelfish.altavista.digital.com/tr) was telling me...

Marc
 
I'll hazard a guess at what you mean for the first part (watch out for
wrap):

foreach (XmlElement field in
doc.SelectNodes("/TRACCIATI/TRACCIATO/TABLE[@NAME='01']/FIELD")) {
Console.WriteLine("{0}: {1},{2}",
field.GetAttribute("NAME"),
field.GetAttribute("START"),
field.GetAttribute("LEN"));
}

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top