Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda