Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
XmlTextReader ignora el segundo y tercer elemento de perfil

Tengo el siguiente archivo XML:

 <?xml version="1.0"?><!--This document contains the profiles that have been created.--><Profiles> <Profile> <name>One</name> <date>Two</date> </Profile> <Profile> <name>One</name> <date>Two</date> </Profile> <Profile> <name>One</name> <date>Two</date> </Profile> </Profiles>

El problema es que cuando uso XmlTextReader, solo lee el primer perfil e ignora el segundo y el tercero.

 public ArrayList ReadProfiles() { ArrayList result = new ArrayList(); Hashtable currentProfile = null; string currentName = ""; string currentValue = ""; XmlTextReader textReader = new XmlTextReader(profilesPath); // Read until end of file while (textReader.Read()) { switch(textReader.NodeType) { case XmlNodeType.Text: { currentValue = textReader.Value; Debug.Log("found text = " + currentValue); } break; case XmlNodeType.Element: { currentName = textReader.Name; switch(currentName) { case "Profiles": Debug.Log("found profiles"); break; case "Profile": Debug.Log("found profile"); break; case "name": Debug.Log("found name"); break; case "date": Debug.Log ("found date"); break; default: Debug.Log("default in"); break; } } break; case XmlNodeType.Comment: Debug.Log("found comment"); break; case XmlNodeType.EndElement: Debug.Log("found end element" + textReader.Name.ToString()); break; default: Debug.Log("default out"); break; } } textReader.Close(); return result; }

entonces obtengo: texto alternativo

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Salida de mi prueba con exactamente el mismo código y datos. Reemplace Debug.Log con Writeline.

 default out found comment found profiles default out found profile default out found name found text = One found end elementname default out found date found text = Two found end elementdate default out found end elementProfile default out found profile default out found name found text = One found end elementname default out found date found text = Two found end elementdate default out found end elementProfile default out found profile default out found name found text = One found end elementname default out found date found text = Two found end elementdate default out found end elementProfile default out found end elementProfiles default out
over 4 years ago · Santiago Trujillo Report

0

Eso no es XML válido. La especificación XML solo permite un nodo raíz (las instrucciones de procesamiento no cuentan como nodos) y su flujo de entrada contiene varios nodos raíz. Si pasa eso por un validador, vomitará.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!