Timeline for How to extract data and attribute data from an XMLElement
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 4, 2020 at 2:26 | comment | added | user74549 | Mike, sorry for the tardy reply. I tried it and it worked. However, I decided to use Cases[] to parse the XML tree. It works quite well now. | |
Sep 23, 2020 at 13:22 | comment | added | Mike Colacino |
@user74549 Try it just like this: trf[fleetXMLString, "BJ#01"]; busAttGL selectedAttr = Cases[busAttGL, XMLElement["Width", ___, ___]][[1]] {selectedAttr[[2]][[1]][[2]], selectedAttr[[3]][[1]]} {"unit" /. First[Cases[selectedAttr, {"unit" -> "Distance"}]], selectedAttr[[3]][[1]]} . The semicolon at the end of the trf call might be missing from yours; then it generates what you wrote above. What's happening is the stack of the recursion is getting printed out when you call trf without the output-suppressing semi-colon. That's why I hacked it with the assignment to a global.
|
|
Sep 23, 2020 at 5:04 | comment | added | user74549 |
Mike, cannot send the notebook because there's too much paperwork to push up the approval chain. This is the header of the output string with "BJ#01" {If[XMLElement["Name", {}, {"BJ#00"}] == XMLElement["Name", {}, {"BJ#01"}], trf[Rest[{XMLElement["Name", {}, {"BJ#00"}], XMLElement[ "Bus", {}, {XMLElement["Shape", {}, {"parallelepiped"}], XMLElement["Length", {"unit" -> "Distance"}, {"0.5"}], XMLElement["Height", {"unit" -> "Distance"}, {"0.3"}], XMLElement["Width", {"unit" -> "Distance"}, {"0.4"}], XMLElement[ ...
|
|
Sep 22, 2020 at 21:37 | comment | added | Mike Colacino | It seems to work in my notebook; of course you need to change the data in BJ#01 to see the difference since the original has the same values for both. If you like, you can mail me your notebook @user74549 and I will take a look at it. [email protected] | |
Sep 22, 2020 at 17:21 | comment | added | user74549 | Thank you Mike. I like the idea of using recursion to strip the XML string to the nodes of interest. However, I have to work on the code sample that you show because when I try it with "BJ#01" it doesn't give the expected string. | |
Sep 22, 2020 at 14:21 | history | edited | Mike Colacino | CC BY-SA 4.0 |
added 12 characters in body
|
Sep 22, 2020 at 14:14 | history | answered | Mike Colacino | CC BY-SA 4.0 |