The first function strips off the document header and the declaration.
The second one pulls off the "Fleet" and maps across the list of vehicles in the fleet, because there are potentially many vehicles.
The third function pulls out the name of the specific vehicle you are looking for (say "BJ#00") with the
IF
statement and then continues the recursion stripping off the "SomeVehicle" XMLElement.The final step takes the list of attributes and stuffs the list into a global list for further processing (maybe not the most elegant part) but I think this is the general solution to the problem you are posing, which at a high level is "how can I extract the traits of a specific vehcile?" This leaves all the traits together in a form can be post-processed as you need.
This looks like
{XMLElement["Shape", {}, {"parallelepiped"}], XMLElement["Length", {"unit" -> "Distance"}, {"0.5"}], XMLElement["Width", {"unit" -> "Distance"}, {"0.4"}], XMLElement["Height", {"unit" -> "Distance"}, {"0.3"}], XMLElement["Density", {"unit" -> "Density"}, {"500.0"}]}
From here you can extract the attributes by manipulating the list directly, or if you prefer you can use
Cases
like this:selectedAttr = Cases[busAttGL, XMLElement["Width", ___, ___]][[1]]
selectedAttr=Cases[busAttGL, XMLElement["Width", ___, ___]][[1]]
{"unit" /. First[Cases[selectedAttr, {"unit" -> "Distance"}]],selectedAttr[[3]][[1]]}
{"unit" /. First[Cases[selectedAttr, {"unit" -> "Distance"}]],selectedAttr[[3]][[1]]}
`{selectedAttr[[2]][[1]][[2]], selectedAttr[[3]][[1]]}`