parsing XML with Compose (OML)

andyer
andyer
Altair Employee
edited May 16 in Community Q&A

Dear learned denizens of the Compose Forum:

I'm interested in parsing an xml file from Compose, I wonder what my options are?  

I would primarily like to work in OML, it looks like I could use python library + python to OML bridge to do this, but is there any option to do this directly in OML?  

I found this example in Octave; however, it requires javaObject(), javaaddpath() to achieve it.

%reference:https://wiki.octave.org/Cookbook#Load_XML_files

Has anyone built something to do this already, or is there any option using OML directly?

Thanks for any advice.

Best,

Andy

Tagged:

Answers

  • RSGarciarivas
    RSGarciarivas
    Altair Employee
    edited May 16

    Hi Andy,

    Whenever I need to parse XMLs, I use function type to read the file's contents as a string and I use function regexp to read specifically what I need and functions fopen, fprintf and fclose to make a copy or overwrite as desired.

    Rafael

  • andyer
    andyer
    Altair Employee
    edited May 16

    Thanks, Rafael, do you have any example(s) you can share to read/write xml?

    Thanks,

    Andy

  • RSGarciarivas
    RSGarciarivas
    Altair Employee
    edited May 16
    andyer said:

    Thanks, Rafael, do you have any example(s) you can share to read/write xml?

    Thanks,

    Andy

    I was unable to find an example in which I used regular expression but, instead, I'm using functions strfind and strrep in this one.

    Using function regexp to handle this with regular expressions gives much more flexibility.

    I'll continue looking for old examples that might be better.

    Rafael

  • andyer
    andyer
    Altair Employee
    edited May 16

    Thanks again, Rafael!  I'll check it out :)

  • RSGarciarivas
    RSGarciarivas
    Altair Employee
    edited May 16
    andyer said:

    Thanks again, Rafael!  I'll check it out :)

    Hi Andy, have a look at this example as well, here I used a regular expression to find what I wanted in an MDL file. The process is the same as for an XML. Hope it's useful.