Exemple #1
0
        private XmlDocument mapNode(XmlDocument destinationDoc, XmlNode destinationParentNode, XmlNode sourceNode)
        {
            try
            {
                // load the xpath from source node
                // x[1]\y[2]\f[1]
                string sourceXPath = XmlUtility.GetDirectXPathToNode(sourceNode);
                // x\y\f
                string sourceXMppingFilePath = XmlUtility.GetXPathToNode(sourceNode);

                //load route from mappingFile of the source node
                XmlMappingRoute route = xmlMapper.GetRoute(sourceXMppingFilePath);

                XmlNode destinationPNode = destinationParentNode;

                // check if this source xpath is mapped in the xmlMapper
                if (xmlMapper.SourceExist(sourceXMppingFilePath))
                {
                    if (!string.IsNullOrEmpty(sourceNode.InnerText) || addAlsoEmptyNode)
                    {
                        // get name of the destination node
                        string destinationTagName = route.GetDestinationTagNames();

                        // get xpath of the destination node
                        // X\XType\Y\F
                        string destinationXMppingFilePath = route.GetDestinationXPath();

                        //ToDo checkif the way to map is intern to extern or extern to intern
                        // X[1]\XType[2]\Y[1]\yType[4]\F[1]\yType[2]
                        string destinationXPath = "";

                        if (this.TransactionDirection == TransactionDirection.ExternToIntern)
                        {
                            destinationXPath = mapExternPathToInternPathWithIndex(sourceXPath, destinationXMppingFilePath);
                        }
                        else
                        {
                            destinationXPath = mapInternPathToExternPathWithIndex(sourceXPath, destinationXMppingFilePath);
                        }

                        // create xmlnode in document

                        XmlNode destinationNode = XmlUtility.GenerateNodeFromXPath(destinationDoc, destinationDoc as XmlNode,
                                                                                   destinationXPath, xmlSchemaManager.Elements, xmlSchemaManager.XmlNamespaceManager); //XmlUtility.CreateNode(destinationTagName, destinationDoc);
                        destinationNode.InnerText = sourceNode.InnerText;

                        //if (type == element), get content
                        if (xmlMapper.IsSourceElement(sourceXPath))
                        {
                        }

                        //destinationParentNode = createMissingNodes(destinationParentXPath, currentParentXPath, destinationParentNode, destinationDoc);

                        ////check if nodes in destination not exist, create them
                        //string destinationParentXPath = route.GetDestinationParentXPath();
                        //string currentParentXPath = XmlUtility.GetDirectXPathToNode(destinationParentNode);
                    }
                }

                if (sourceNode.HasChildNodes)
                {
                    foreach (XmlNode childNode in sourceNode.ChildNodes)
                    {
                        destinationDoc = mapNode(destinationDoc, destinationPNode, childNode);
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }

            return(destinationDoc);
        }