using System.Xml.Linq; using Serilog; using CRIF.ACTion.Common; using CRIF.ACTion.Common.Parsers; namespace CRIF.ACTion.Configuration { public class ProductDetailsResponseParser : IResponseParser> { private const string _productDetailsPath = "/actionAPI/getProducts/msg:maintExportResponse/msg:maintenanceEntities/maint:maintenanceEntity/maint:products/common:product/common:productCategory"; public ProductDetailsResponseParser() { } public Dictionary Parse(XElement xElement) { Dictionary mappingList = []; try { var namespaceManager = CrifNamespaces.GetNamespaceManager(xElement); IEnumerable channelNodeList = xElement.XElementXPathSelectElements(_productDetailsPath, namespaceManager); foreach (XElement channelNode in channelNodeList) { try { string productId = channelNode.Parent.Attribute(CrifNamespaces.Common + "productID").Value; string categoryId = channelNode.Attribute(CrifNamespaces.Common + "productCategoryID").Value; mappingList.Add(productId, categoryId); } catch (Exception ex) { Log.Error("Error trying to parse CRIF Product information from node in Configuration Response", ex.Message, ex.StackTrace); } } } catch (Exception ex) { Log.Error("Error trying to parse CRIF Products Configuration Response", ex.Message, ex.StackTrace); } return mappingList; } } }