PDA

Ver la Versión Completa : No entiendo XML


MaxiDucoli
24-09-2017, 02:19:18
Hola, ya leí varios post con mucha ayuda sobre XML y no entiendo.
Me siento muy estúpido, pero es así.
No entiendo qué hacer para recorrer los no sé qué de los XML-

Les cuento.
Tengo un XML que lo paso por el XML Binding, me genera un PAS que calculo sea algo generado para trabajar directamente en ese archivo, no lo entiendo.
Me leo y veo videos de trabajar en XML y no entiendo.
Quizás sea ya (ES DE HECHO NO QUEDAN DUDAS) problema de mi cabeza.
Pero no sé como recorrer y leer los ficheros XML, ni aún viendo que el en XMLBinding me ha hecho algo servido en bandeja, por que más o menos entiendo lo que hizo, pero no sé hacer con eso.

Les dejo parte del XML que quiero leer, lo que quiero hacer es entrar en un (NODO??) llamado <game>, leer su contenido y si es necesario, agregar un (HIJO????) a ese (NODO??)

Me ayuda alguien por favor??
De verdad leí un montón, vi videos DEMASIADO EXPLICATIVOS!!!, bajé ejemplos y NI ASÍ PUDE!!!



PARTE DEL XML ( Son como 9000 sub items, pero con que me sepa leer 1 calculo que un for o while o o que sea me va a servir después)


<?xml version="1.0" encoding="UTF-8"?>
<gameList>
<game id="005" source="mamedb.blu-ferret.co.uk">
<path>./005.zip</path>
<name>005 </name>
<desc>Agent 005 brings new cash collections to you. His mission is to deliver secret attache cases to an awaiting helicopter. Through wily street chases and the shadows of warehouse darkness to slippery skating tink maneuvers and the blazing aerial getaway fight. Agent 005 steels the scene and delivers customers to you. Fun-filled music attracts them. Four thrilling escape scenes challenge them and the continuous fun keeps them playing and playing. The unique audio and video excitement matches every players skill level,&#xA;&#xA;And 005 is a RasterScan Convert, a Game which can later be converted to a brand new top earning game at a substantial savings.&#xA;&#xA;Put Agent 005 on your side and win the chase for higher profits. For more information on the latest in video-game action, call your nearest Sega/Gremlin distributor.&#xA;&#xA;The chase is on. Agent 005 makes away with an attache case. A hovering helicopter awaits his arrival, but first... Enemy guards pound the street in pursuit. 005 must duck into a new scene.&#xA;&#xA;Inside a warehouse. Avoid being caught in the guard's flashlight beams... once 005 is detected, the chase quickens to super fast. Blast the guards with stun-gas and score valuable points.&#xA;&#xA;Slip into a skate rink. And slip you will. There is no stopping on ice and the same goes for the thrills. Sliding and firing... firing and sliding. 005 can call his helicopter to escape.&#xA;&#xA;The final flight fight. High flying aerial excitement. 005 has reached his helicopter in all other scenes and now finds his high scoring, high soaring getaway copter in a new test balloon and parachute bombs close in from all sides. 005 blast away to score points and to escape. Then the final challenge is thrown at his skill - a blazing battle with the enemy copter. Win now and you win big.&#xA;&#xA;It's free-wheeling fun with fun-filled music and sound. Its stealth and pursuit is like no other video game. Everybody's after Agent 005. You should be, too. Call your nearest Sega/Gremlin distributor today and make sure 005 is on your side.&#xA;&#xA;</desc>
<rating>0.618</rating>
<image>/home/pi/RetroPie/roms/arcade/boxart/005.png</image>
<marquee>/home/pi/RetroPie/roms/arcade/wheel/005.png</marquee>
<video>/home/pi/RetroPie/roms/arcade/snap/005.mp4</video>
<releasedate>1981</releasedate>
<developer>Sega</developer>
<publisher></publisher>
<genre>Maze / Shooter Small</genre>
<players>2</players>
</game>
<game id="10yard" source="mamedb.blu-ferret.co.uk">
<path>./10yard.zip</path>
<name>10-Yard Fight (World, set 1) </name>
<desc>North American release. For more information about the game itself, please see the original Japanese version entry; "10-Yard Fight [Model IF-02]".&#xA;&#xA;Description from the USA back cover:&#xA;&#xA;You're the quarterback in this amazingly real football game!&#xA;&#xA;Enjoy realistic grid-iron action as you move your team up and down the field to victory! Run, pass, kick, punt -- you call the plays in this true-to-life football game. Play against the computer, or against a friend, for hours of real football action. The sights, the sounds and the plays are so real, you'll think you're right on the fifty yard line!&#xA;&#xA;</desc>
<rating>0.471</rating>
<image>/home/pi/RetroPie/roms/arcade/boxart/10yard.png</image>
<marquee>/home/pi/RetroPie/roms/arcade/wheel/10yard.png</marquee>
<video>/home/pi/RetroPie/roms/arcade/snap/10yard.mp4</video>
<releasedate>1983</releasedate>
<developer>Irem</developer>
<publisher></publisher>
<genre></genre>
<players>2</players>
</game>
</gameList>

Gracias de ante mano a alguien.

Casimiro Notevi
24-09-2017, 11:20:17
Realmente no tiene mucho que entender, imagina que en lugar de un .xml fuese un .ini

[game id="005"]
source="mamedb.blu-ferret.co.uk"
path=./005.zip
name=005
desc=Agent 005 brings new cash collections to you. His mission is to deliver secret attache cases to an awaiting helicopter.
rating=0.618
image=/home/pi/RetroPie/roms/arcade/boxart/005.png
marquee=/home/pi/RetroPie/roms/arcade/wheel/005.png
video=/home/pi/RetroPie/roms/arcade/snap/005.mp4
releasedate=1981
developer=Sega
publisher=
genre=Maze / Shooter Small
players=2

[game id="10yard"]
source="mamedb.blu-ferret.co.uk"
path=./10yard.zip
name=10-Yard Fight (World, set 1)
desc=North American release. For more information about the game itself, please see the original Japanese version entry;
rating=0.471
image=/home/pi/RetroPie/roms/arcade/boxart/10yard.png
marquee=/home/pi/RetroPie/roms/arcade/wheel/10yard.png
video=/home/pi/RetroPie/roms/arcade/snap/10yard.mp4
releasedate=1983
developer=Irem
publisher=
genre=
players=2

mamcx
24-09-2017, 17:42:27
Existe un numero realmente pequeño de conceptos universales en la programación. De esto, el creador de PASCAL determino que:

PROGRAMA = DATOS + ALGORITMOS

Donde muchos se pierden es que solo se preocupan por los algoritmos, sin pensar en los datos. Aqui "datos" se refiere a LA ESTRUCTURA DE LOS DATOS, no meramente a su contenido como lo veríamos ingenuamente, ni tampoco a su *implementación concreta* ya que esta puede cambiar (aunque exista una forma canonica de hacerlo en la programación), sino literalmente, a su estructura o FORMA.

Basicamente, hay un pequeño conjunto de "formas" generales, que a nivel abstracto son lo mismo, pero que se *implementan* de formas diversas.

Pero estas formas generales (*DATOS*) se operan de forma igual con sus correspondientes (*ALGORITMOS*)!

Asi que el "truco" es pensar: Que forma de datos estoy operando, asi sabre que algoritmos le aplican.

-----

Estas son las siguientes. Lease "Valores de tipo ....":
P.D: Coloco el valor + el Tipo/Type

- Unitarios/Scalars: 1:int, true:bool, "hello":string, cliente:Object(Customer)

Se podria decir que un scalar es un caso especial de las siguientes formas de grupo:

- Colecciones/Listas - Collections/List: [1, 2, 3]
que pueden ser representados como: Arrays, LinkedLists, Queue, InifiniteSequences, etc

Esta es la forma mas familiar

- Tablas/Relaciones/Relations/DataSets/Tables: Clientes:TDataSet, Ciudades:HashMap[NombreCampo:ArrayOf...], etc

Estas son un poco mas complejas, son estructuras de 2 dimensiones, y son el fundamento de la bases de datos relacionales. Se podria decir que los escalares y las listas son casos especiales de las relacionales

- Grafos/Arboles/Graphs/Trees: Cuentas:BTree, Genealogia:AVTree, *XML:Tree*

Y por ultimo los grafos, con su mucho mas util (osea, en la practica) caso especial de los arboles (https://es.wikipedia.org/wiki/%C3%81rbol_(inform%C3%A1tica)) <-- LEE ESTO.

Un XML es de esta familia. Es simplemente una forma de *serializar* o convertir a una forma que permita ser almacenada en disco, un arbol *cualquiera*.

Puedes usar un visualizador grafico, que permite darse cuenta de esto, como:

https://codebeautify.org/xmlviewer

XML es *complejo*. De ser posible, es mejor usar algo como Json o similar.

-----
La parte importante es que cada "forma" tiene un numero finito y corto de tareas universales que se hacen con estas. Por ejemplo un lista:

- Crear
- Recorrer valor a valor
- Ir a la posición X (que puede derivarse de la anterior!)
- Determinar si es finita o infinita (mirar sus tamaño)

Y ya. Puede que adicionalmente se permita modificar la lista, pero estas tres tareas son todo lo que se necesita para hacer TODAS LAS DEMAS.

Igualmente, los arboles tienen un conjunto pequeño de tareas.

Entre estos, el importante es:

- Recorrer el arbol:

https://es.wikipedia.org/wiki/Recorrido_de_%C3%A1rboles

Una vez que domines como operar un arbol de forma generica, ya veras que "pasar" a XML es "pan comido", de la misma manera que si entiendes como se opera una matriz volverla un archivo plano no es nada del otro mundo.

Neftali [Germán.Estévez]
26-09-2017, 08:59:04
En mi web puedes encontrar algunas entradas donde se explica cómo acceder a archivos XML utilizando justamente el XML Mapper.
Puedes revisar los pasos para generar el fichero y luego para acceder a los datos y echarle un vistazo a los ejemplos que acompañan los artículos.

http://neftali.clubdelphi.com/cargar-fichero-gpx-xml-y-acceder-a-los-datos/
http://neftali.clubdelphi.com/testeando-xe2-aplicacion-firemonkey/