Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse AMESim fmu xml file #5

Open
LMerCy opened this issue Oct 30, 2018 · 2 comments
Open

Cannot parse AMESim fmu xml file #5

LMerCy opened this issue Oct 30, 2018 · 2 comments

Comments

@LMerCy
Copy link

LMerCy commented Oct 30, 2018

When i use this project to call fmu generated by AMESim (FMI 2.0 Co-simulation ), Why this happens:
Parser error. Depth wrong after parsing sub-tree for Tool
What does this error mean?

@cxbrooks
Copy link
Owner

The error message comes from https://github.com/cxbrooks/fmusdk2/blob/master/fmu20/src/shared/parser/XmlParser.cpp line 159:

void XmlParser::parseChildElements(Element *el) {
    int elementIsEmpty = xmlTextReaderIsEmptyElement(xmlReader);
    if (elementIsEmpty == -1) {
        throw XmlParserException("Error parsing xml file '%s'", xmlPath);
    } else if (elementIsEmpty == 1) {
        return;
    }

    bool ret = readNextInXml();
    while (ret  && xmlTextReaderNodeType(xmlReader) != XML_READER_TYPE_END_ELEMENT) {
        if (xmlTextReaderNodeType(xmlReader) == XML_READER_TYPE_ELEMENT) {
            const char *localName = (char *)xmlTextReaderConstLocalName(xmlReader);
            int depthBefore = xmlTextReaderDepth(xmlReader);
            int isEmptyElement = xmlTextReaderIsEmptyElement(xmlReader);
            el->handleElement(this, localName, isEmptyElement);
            if (!isEmptyElement) {
                int depthAfter = xmlTextReaderDepth(xmlReader);
                if (depthBefore != depthAfter) {
                    throw XmlParserException("Parser error. Depth wrong after parsing sub-tree for %s.", localName);
                }
            }
        }
        ret = readNextInXml();
    }
    if (!ret) {
        throw XmlParserException("Error parsing xml file '%s'", xmlPath);
    }
}

I suggest unzipping the .fmu file and running an xml validator on the modelDescription.xml file. See https://en.wikipedia.org/wiki/XML_validation for links to xmllint and an online validator.

If your modelDescription.xml file is valid .xml, then there is probably a bug somewhere in the fmusdk code. To fix this, you would need to add print statements to the code to see where in the modelDescription.xml file the problematic section is located.

If your modelDescription.xml file is valid .xml, then it would help if you uploaded the modelDescription.xml file.

However, I'm retired, so I'm not that interested in fixing bugs myself in this code, though I'd accept well executed push requests.

https://github.com/cxbrooks/fmusdk2 says:

Port of FMUSDK2.0.3 from QTronic (http://www.qtronic.de/doc/fmusdk.zip) to Mac OS X and Linux.

This code is no longer being maintained, please take a look at

https://resources.qtronic.de/fmusdk/FmuSdk_reference.html

for more recent versions.

So, you could also try the qtronic.de version of FmuSdk, which is newer than this version.

If your modelDescription.xml file is invalid .xml, then try FmuSdk, then follow up with Siemens, the manufacturers of AMESim.

@LMerCy
Copy link
Author

LMerCy commented Nov 1, 2018

@cxbrooks thanks for your help! The modelDescription.xml is valid, i have solved the problem with qtronic.de version of FmuSdk. It seems that there are some bugs during parsing xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants