diff --git a/struct.go b/struct.go index ac00171..56c0735 100644 --- a/struct.go +++ b/struct.go @@ -72,6 +72,7 @@ validationXSDInfos string validationSchemaErrors []ErrorXML xpath json.RawMessage + xpathError string } type GeneralInfo struct { diff --git a/xml.go b/xml.go index 5ce93b8..ce9ef87 100644 --- a/xml.go +++ b/xml.go @@ -32,7 +32,7 @@ xmlInfo, logger := CheckIfXmlIsWellFormed(message.path, logger) if *configurationFolder != "" && len(xmlInfo.data) > 0 { _, logger = CheckXMLValidation(message.path, xmlInfo, logger) - _, logger = ProcessXpath(xmlInfo, logger) + _, logger = ProcessXpath(message.path, xmlInfo, logger) } logger.Info("") UpdateCounter() @@ -220,7 +220,7 @@ return xmlDetailled, logger } -func ProcessXpath(xmlInfo XMLInfo, logger *logrus.Entry) (DetailledAnalysis, *logrus.Entry) { +func ProcessXpath(xmlPath string, xmlInfo XMLInfo, logger *logrus.Entry) (DetailledAnalysis, *logrus.Entry) { doc, err := xmlquery.Parse(strings.NewReader(xmlInfo.data)) detailledInfo := DetailledAnalysis{} @@ -271,13 +271,19 @@ finalXpath := []byte(tmpXpath) jsonData := XpathStructure{} - json.Unmarshal(finalXpath, &jsonData) + error := json.Unmarshal(finalXpath, &jsonData) - detailledInfo.xpath = finalXpath - - logger = logger.WithFields(logrus.Fields{ - "xpath": detailledInfo.xpath, - }) + // if no error add xpath to analyze + if error == nil { + detailledInfo.xpath = finalXpath + logger = logger.WithFields(logrus.Fields{ + "xpath": detailledInfo.xpath, + }) + } else { + logger = logger.WithFields(logrus.Fields{ + "xpathError": "File " + xmlPath + " : " + error.Error(), + }) + } } return detailledInfo, logger diff --git a/xml_test.go b/xml_test.go index 2a4bb3f..1c1b2b0 100644 --- a/xml_test.go +++ b/xml_test.go @@ -92,6 +92,6 @@ assert.Equal(t, resultWellFormed.doctype.Sysid, "JATS-journalpublishing1.dtd", "Doctype is valid") assert.Equal(t, resultWellFormed.isWellFormed, true, "XML is well formed") assert.Equal(t, resultWellFormed.wellFormedErrors, ErrorXML{}, "Return empty if xml is not well formed") - resultXpath, _ := ProcessXpath(resultWellFormed, contextLogger) + resultXpath, _ := ProcessXpath(xmlData.path, resultWellFormed, contextLogger) assert.Equal(t, len(resultXpath.xpath), 659, "xpath is present") }