2

I am trying to parse the XML data from the output of cppcheck. But the XML structure seems wrong.

cppcheck src --enable=warning,style,unusedFunction --xml --inconclusive --std=posix --std=c++11 2> error_s.xml

cppcheck XML output:

<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
    <cppcheck version="1.82"/>
    <errors>
        <error id="funcArgNamesDifferent" severity="style" msg="Blah Blah bLah." verbose="Blah Blah Verbose" cwe="628" inconclusive="true">
            <location file="src/DataLayer/ABC.cpp" line="329"/>
            <location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
            <location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
            <location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
        </error>
</errors>
</results>

Shouldn't the location node be inside an array like locations?

        <locations>
            <location file="src/DataLayer/ABC.cpp" line="329"/>
            <location file0="src/DataLayer/ABC.cpp" file="src/DataLayer/ABC.h" line="64"/>
        </locations>
orbitcowboy
  • 1,438
  • 13
  • 25
zubair Shaik
  • 395
  • 6
  • 16
  • I tested your posted XML with a few online XML validators and they all said it was perfectly fine. – Jesper Juhl Jul 01 '20 at 14:03
  • yea because it checks for basic validation ... but how do you get the value of second location node..? for ex: in php if i do ```$cpp_error['location']``` -> it points to first location then it produces warning. – zubair Shaik Jul 01 '20 at 14:08
  • 2
    @Hahn have you tried `$cpp_error['location'][2]`? I don't see the need for a `locations` array. You would have the same problem accessing the second `location` within that `locations` array. You need something like: https://stackoverflow.com/questions/4007413/xpath-query-to-get-nth-instance-of-an-element – rturrado Jul 01 '20 at 15:00

1 Answers1

0

unfortunately it cannot be accessed with out writting too many if-statements ..

if(isset($location)){

}

Conversation with CppChecker Developer.. Hopefully it would get fixed when they release v3

for now, the only way to access is using too many if-Statements.

if not, there is also library htmlreport which will generate html pages..

zubair Shaik
  • 395
  • 6
  • 16