c# - How to easily traverse a deserialized Xml document? -
i trying make importer collada(.dae) files, based on xml. have xml file deserialized objects can access. example, .dae file may have setup this...
<library_geometries> <geometry id="cube1s_008-mesh" name="cube1s.008"> <mesh> <source id="cube1s_008-mesh-positions"> <float_array ...... /> </source> <source id="cube1s_008-mesh-normals"> </source> <vertices id="cube1s_008-mesh-vertices"> <input semantic="position" source="#cube1s_008-mesh-positions"/> </vertices> </mesh> </geometry> <geometry> .... </geometry> </library_geometries>
it deserialized (with xmlserializer.deserialize) in similar fashion. access second "source" in "mesh" library_geometries.geometry[0].mesh.source[1];
all there, problem running traversing deserialized xml document.
for example, in "vertices" there source="#cube1s_008-mesh-positions" means "to access vertices data, go source id of "cube1s_008-mesh-positions"". want go vertices directly source, or anything, has id. library_geometries.geometry[0].mesh.vertices.gotosource(); , can library_geometries.geometry[0].mesh.vertices.gotosource().float_array.values;
i assuming need reflection. perhaps search field has [xmlattribute("id")] , somehow return object in proper type. ideas appreciated.
there 2 basic methods can use.
1) build dictionary 2) add new property geometry geometry class veritices nonserialize. after deserialize, enumerate through classes adding value property geometry.