A pesar de la publicación de XML válido (no nodo raíz), una forma fácil para iterar a través de los <FieldRef> elementos es utilizar el XmlReader.ReadToFollowing
método:
//Keep reading until there are no more FieldRef elements
while (reader.ReadToFollowing("FieldRef"))
{
//Extract the value of the Name attribute
string value = reader.GetAttribute("Name");
}
Por supuesto una interfaz más flexible y fluida es proporcionado por LINQ a XML, ¿tal vez sería más fácil usarlo si estuviera disponible dentro del marco .NET al que se dirige? El código se convierte entonces en:
using System.Xml.Linq;
//Reference to your document
XDocument doc = {document};
/*The collection will contain the attribute values (will only work if the elements
are descendants and are not direct children of the root element*/
IEnumerable<string> names = doc.Root.Descendants("FieldRef").Select(e => e.Attribute("Name").Value);
¿Qué código han intentado? –
¿Cuál es el resto del XML? El XML válido debe tener un nodo raíz. – wsanville