• Search
  • Register
  • Log in
  • The Math Root » Matlab
  • XML Toolbox for MATLAB
  •  
    User has not uploaded an avatar

    I have been trying to use this for quite a while, but i just cant understand how to retrieve data from a .XML file in MATLAB.

    I have an XML file with 2 important variables i need to retrieve the value for. These are 'A' and 'B'. There are many different values for 'A' and 'B' and i would like to parse the .XML file to save all values for 'A' are saved into an array and all values for 'B' are saved into an array.

    I have read a tutorial but i still cant figure it out.

    Any help would be much appreciated.

    Thanks,
    Lucy

    #21
    Lucy
    Member
    Posted 6 months ago
     
    User has not uploaded an avatar

    % Presuming the variables are stores as elements, and the file is like this:
    % <xml>
    % 10
    % </xml>

    % Read the xml file into memory:

    docNode = xmlread( 'insert_your_filename_here.xml' );

    % Then you just use the JAVA DOM (http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Element.html)
    % For example, to retrieve the nodes for the elements A and B:

    ANodeList = docNode.getElementsByTagName('A'); % returns a reference to all the A elements, i.e. everything in the xml with this pattern ..

    %Iterate over the node list to read the values of A
    for i = 1:ANodeList.getLength()
    A(i) = ANodeList.ANodeList.item(i-1).getNodeValue
    end

    % of course, everything you read is a string, so if they are numeric variables, you need to use str2double() to make them numeric
    ANumeric = str2double(A);

    #22
    pmacaodh
    Member
    Posted 6 months ago
     
    User has not uploaded an avatar

    By the way, you can copy the above into Matlab as is to try it out. Just change the filename and ensure it is in your current working directory.

    Of course, this message board interpreted my example XML elements as a HTML 'A' hyperling tag. The example was meant to look like so:

    <xml>
    <AA>42</AA>
    <B>12</B>
    </xml>

    ...and so on.

    #23
    pmacaodh
    Member
    Posted 6 months ago
     
    User has not uploaded an avatar

    Hello,

    I have to design a program in Matlab to calculate different plots from XML template.
    I mean, I have a xml with some specifications according to a DTD document. The template is not unique, the user can change the template to obtain different things. My goal is to design a program what interpretes the xml template (either xml template with the requirements of the DTD) and to obtain the correspondence output.

    I have read about this and I am sure that the first step is to use 'xmlread'. I have found some functions like .getElementsByTagName but I am not sure how to manage because I have never programmed in Java and I don't know how to read all the variables that I have in my xml. Also, I don't know how to visualize in Matlab this information.

    If someone can help, please, it would be really useful for me.
    Thanks,
    Anna

    #24
    anna
    Member
    Posted 5 months ago
    RSS feed for this topic  

    Reply

    You must log in to post.

      Tags:

  •  © 2009 Anil Kandangath. All posts are owned by the whoever posted them. Share your knowledge.
    The Math Root is proudly powered by bbPress.. This site is not affiliated with The MathWorks™ or Wolfram Research. //   Theme by Mike Lothar  
    [ Time : 0.174s | 12 Queries ]