How to get the info from xml tag ?
Afficher commentaires plus anciens
Hi all,
If I wish to use xml2struct lib https://www.mathworks.com/matlabcentral/fileexchange/28518-xml2struct, and
if I have the following xml file:
<edge id="juncons1" from="232207661" to="232207435" priority="7">
<lane id="juncons1_0"/>
<edge />
How to get the data 'id', 'from' and 'to' info from the edge tag.
I tried to use
xmlhandler = xml2struct( 'my_xml_file_path' );
xmledgeID = xmlhandler.net.edge.Attributes
but it didnt return the d="juncons1" from="232207661" to="232207435" info to the matlab
6 commentaires
Suresh
le 22 Déc 2022
hi, here what is my_xml_file_path?
can you please explain how can i define my_xml_file_path...i have working on reading xml file in matab script and i have to extract scenario_ts id:
pls help me
Image Analyst
le 22 Déc 2022
@Image Analyst, thanks for your update..
xmlhandler = xml2struct( 'C:\UserData\git_ws\curvature_controller\source\curv_ctrl_mod_coord\tests\CurvCtrlModCoord_TL.xml' );
xmlscenario_tsID = xmlhandler.scenario_ts.Attributes
i am trying above code but i am getting like error
reference to non-existent field 'scenario_ts'.
Error in xml_in (line 20)
xmlscenario_tsID = xmlhandler.scenario_ts.Attributes
Image Analyst
le 23 Déc 2022
@Suresh start your own discussion thread and attach your XML file, and m file, zipped up together.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
@Image Analyst thanks for your suggestion, i have uploaded xml file and along with my code
i would like to extract scenario_ts under this tag i need data and need to save in one variable.
currently i m using matlab 2020b while running my code i m getting error like
reference to non-existent field 'scenario_ts'.
Error in xml_in (line 20)
xmlscenario_tsID = xmlhandler.scenario_ts.Attributes.
Image Analyst
le 27 Déc 2022
Modifié(e) : Image Analyst
le 27 Déc 2022
@Suresh Rather than hijacxk @Lawrence Soon's 6 year old post, can you start a discussion thread of your own? I already have it working and I'll post it in your new discussion thread.
Réponses (1)
Kojiro Saito
le 23 Sep 2017
First, you xml file is not ended with proper tag.
The last line
<edge />
should be changed to
</edge>
The whole xml file would be the following.
<edge id="juncons1" from="232207661" to="232207435" priority="7">
<lane id="juncons1_0"/>
</edge>
Also, based on the xmlhandler structure,
xmledgeID = xmlhandler.edge.Attributes
will return the xml information properly.
xmledgeID =
struct with fields:
from: '232207661'
id: 'juncons1'
priority: '7'
to: '232207435'
1 commentaire
Suresh
le 22 Déc 2022
hi, here what is my_xml_file_path?
can you please explain how can i define my_xml_file_path...i have working on reading xml file in matab script and i have to extract scenario_ts id:
pls help me
Catégories
En savoir plus sur Structured Data and XML Documents dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!