XML: Count how many <Tags>
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nycholas Maia
el 3 de En. de 2019
Comentada: Sean de Wolski
el 7 de En. de 2019
I have a big XML file and I would like to count how many a specific tag 'X' appears in this text file.
Example: In this example I have a total of 4 X tags in the whole XML file
%% === HERE I HAVE 3 'X Tags' in the XML Level 3 ===
<A> % Level 1
<B> % Level 2
<X> % Level 3
"Some text 1"
</X>
<X> % Level 3
"Some text 2"
</X>
<X> % Level 3
"Some text 3"
</X>
</ B>
</A>
%% === HERE I HAVE ONLY 1 'X Tag' in the XML Level 3 ===
<A> % Level 1
<B> % Level 2
<X> % Level 3
"Some text 4"
</X>
</ B>
</A>
%% === HERE I DON'T HAVE ANY 'X Tag' in the XML Level 3, AND THE LEVEL 3 DOESN'T EXISTS TOO ===
<A> % Level 1
<B> % Level 2
</ B>
</A>
How can I count the total amount of 'X' tags and get a good performace and small time to compute it?
0 comentarios
Respuesta aceptada
Sean de Wolski
el 3 de En. de 2019
Something along these lines:
xml = xmlread(xmlfile);
Xtag = xml.getElementsByTagName('X');
Xtag.getLength
4 comentarios
Sean de Wolski
el 7 de En. de 2019
s = string(fileread(xmlfile))
xs = extractBetween(s, "<x", "</x>")
numel(xs)
Or similar.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!