| 145 | } |
| 146 | |
| 147 | function _parseXml(xmlToParse, next) { |
| 148 | return parseString(xmlToParse, (err, result) => { |
| 149 | if (err || !result || !result.Delete || !result.Delete.Object) { |
| 150 | return next(errors.MalformedXML); |
| 151 | } |
| 152 | const json = result.Delete; |
| 153 | // not quiet is the default if nothing specified |
| 154 | const quietSetting = json.Quiet && json.Quiet[0] === 'true'; |
| 155 | // format of json is |
| 156 | // {"Object":[ |
| 157 | // {"Key":["test1"],"VersionId":["vid"]}, |
| 158 | // {"Key":["test2"]} |
| 159 | // ]} |
| 160 | const objects = []; |
| 161 | for (let i = 0; i < json.Object.length; i++) { |
| 162 | const item = json.Object[i]; |
| 163 | if (!item.Key) { |
| 164 | return next(errors.MalformedXML); |
| 165 | } |
| 166 | const object = { key: item.Key[0] }; |
| 167 | if (item.VersionId) { |
| 168 | object.versionId = item.VersionId[0]; |
| 169 | } |
| 170 | objects.push(object); |
| 171 | } |
| 172 | return next(null, quietSetting, objects); |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * decodeObjectVersion - decode object version to be deleted |