/// <summary> Constructor for a new instance of the <see cref="GenericXmlMappingPath"/> class </summary> public GenericXmlMappingPath(GenericXmlPath XmlPath) { this.XmlPath = XmlPath; Instructions = new PathMappingInstructions(); }
private void recursive_get_values(XmlReader readerXml, Stack<GenericXmlNode> currentStack, List<GenericXmlPathValue> returnValue) { // Create the list of nodes to this point from the stack List<GenericXmlNode> currentReverseList = currentStack.ToList(); // THis is now on THIS element, so move to the next, unless there were none if (!readerXml.Read()) return; // Check to see if this node has been added yet // Create the path for this GenericXmlPath currentPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { currentPath.PathNodes.Add(currentReverseList[j]); } //// Was this already added? //string currentPathString = currentPath.ToString(); //if (!pathExistenceCheck.ContainsKey(currentPathString)) //{ // pathExistenceCheck[currentPathString] = currentPathString; // returnValue.Add(currentPath); //} // First, handle any attributes if (readerXml.HasAttributes) { // Create the list of nodes to this point for (int i = 0; i < readerXml.AttributeCount; i++) { // Move to this attribute readerXml.MoveToAttribute(i); // Create the path for this GenericXmlPath thisPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { thisPath.PathNodes.Add(currentReverseList[j]); } thisPath.AttributeName = readerXml.Name; // Get the value for this path string attributeValue = readerXml.Value; // Add this path/value pair to the return value returnValue.Add(new GenericXmlPathValue(thisPath, attributeValue)); } // Move back to the main element after handing the attributes readerXml.MoveToElement(); } //// THis is now on THIS element, so move to the next, unless there were none //if (!readerXml.Read()) return; //// Is there actual text for this element //if ( !String.IsNullOrEmpty(readerXml.Value)) //{ // // Create the path for this // GenericXmlReaderMapperPath thisPath = new GenericXmlReaderMapperPath(); // for (int j = currentReverseList.Count - 1; j >= 0; j--) // { // thisPath.PathNodes.Add(currentReverseList[j]); // } // // Was this already added? // string pathString = thisPath.ToString(); // if (!pathExistenceCheck.ContainsKey(pathString)) // { // pathExistenceCheck[pathString] = pathString; // returnValue.Add(thisPath); // } //} // Now, iterate through all the child elements that may exist while (readerXml.Read()) { if (readerXml.NodeType == XmlNodeType.Text) { // Create the path for this GenericXmlPath thisPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { thisPath.PathNodes.Add(currentReverseList[j]); } // Get the value for this path string textValue = readerXml.Value; // Add this path/value pair to the return value returnValue.Add(new GenericXmlPathValue(thisPath, textValue)); } if (readerXml.NodeType == XmlNodeType.Element) { // Create the node for this top-level element string nodeName = readerXml.Name; GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName }; // Add this to the stack currentStack.Push(topNode); // Recursively read this and all children recursive_get_values(readerXml.ReadSubtree(), currentStack, returnValue); // Since this node was handled, pop it off the stack currentStack.Pop(); } } }
private void recursive_process_file(XmlReader readerXml, Stack<GenericXmlNode> currentStack, GenericXmlMappingSet set, GenericXmlReaderResults returnValue) { // Create the list of nodes to this point from the stack List<GenericXmlNode> currentReverseList = currentStack.ToList(); // THis is now on THIS element, so move to the next, unless there were none if (!readerXml.Read()) return; // Create the path for this GenericXmlPath currentPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { currentPath.PathNodes.Add(currentReverseList[j]); } //// First, handle any attributes //if (readerXml.HasAttributes) //{ // // Create the list of nodes to this point // for (int i = 0; i < readerXml.AttributeCount; i++) // { // // Move to this attribute // readerXml.MoveToAttribute(i); // // Create the path for this // GenericXmlPath thisPath = new GenericXmlPath(); // for (int j = currentReverseList.Count - 1; j >= 0; j--) // { // thisPath.PathNodes.Add(currentReverseList[j]); // } // thisPath.AttributeName = readerXml.Name; // // Get the value for this path // string attributeValue = readerXml.Value; // // Does mapping exist for this path? // PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath); // // If instructions, this was mapped // if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping))) // { // MappedValue thisMappedValue = new MappedValue(); // thisMappedValue.Mapping = instructions.SobekMapping; // thisMappedValue.Path = thisPath; // thisMappedValue.Value = attributeValue; // returnValue.MappedValues.Add(thisMappedValue); // } // } // // Move back to the main element after handing the attributes // readerXml.MoveToElement(); //} // Now, iterate through all the child elements that may exist while (readerXml.Read()) { //if (readerXml.NodeType == XmlNodeType.Text) //{ // // Create the path for this // GenericXmlPath thisPath = new GenericXmlPath(); // for (int j = currentReverseList.Count - 1; j >= 0; j--) // { // thisPath.PathNodes.Add(currentReverseList[j]); // } // // Does mapping exist for this path? // PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath); // // Get the value for this path // string textValue = readerXml.Value; // // If instructions, this was mapped // if ((instructions != null) && ( !String.IsNullOrEmpty(instructions.SobekMapping))) // { // MappedValue thisMappedValue = new MappedValue(); // thisMappedValue.Mapping = instructions.SobekMapping; // thisMappedValue.Path = thisPath; // thisMappedValue.Value = textValue; // returnValue.MappedValues.Add(thisMappedValue); // } //} bool text_found = false; if (readerXml.NodeType == XmlNodeType.Element) { // Create the node for this top-level element string nodeName = readerXml.Name; GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName }; // Add this to the stack currentStack.Push(topNode); if (topNode.NodeName == "text") text_found = true; // It may be that mapping exists right here at this level // Create the path for this currentReverseList = currentStack.ToList(); GenericXmlPath thisPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { thisPath.PathNodes.Add(currentReverseList[j]); } // Does mapping exist for this path? if (set.Contains_Path(thisPath)) { // Collect the attributes FIRST List<Tuple<string, string>> attributes = null; if (readerXml.HasAttributes) { attributes = new List<Tuple<string, string>>(); readerXml.MoveToFirstAttribute(); attributes.Add(new Tuple<string, string>(readerXml.Name, readerXml.Value)); while (readerXml.MoveToNextAttribute()) { attributes.Add(new Tuple<string, string>(readerXml.Name, readerXml.Value)); } readerXml.MoveToElement(); } // Does mapping exist for this path? PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath); // If instructions, this was mapped if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)) && (instructions.IgnoreSubTree)) { MappedValue thisMappedValue = new MappedValue(); thisMappedValue.Mapping = instructions.SobekMapping; thisMappedValue.Path = thisPath; if (instructions.RetainInnerXmlTags) { thisMappedValue.Value = readerXml.ReadInnerXml(); } else { StringBuilder builder = new StringBuilder(); XmlReader innerReader = readerXml.ReadSubtree(); while (innerReader.Read()) { if (innerReader.NodeType == XmlNodeType.Text) { builder.Append(innerReader.Value); } } thisMappedValue.Value = builder.ToString(); } returnValue.MappedValues.Add(thisMappedValue); //// Actually, there is something here about skipping this //readerXml.Skip(); } else { // Recursively read this and all children recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue); } // Now, handle the attributes if ((attributes != null) && (attributes.Count > 0)) { foreach (Tuple<string, string> attribute in attributes) { // Does mapping exist for this path? PathMappingInstructions attrInstructions = set.Get_Matching_Path_Instructions(thisPath, attribute.Item1); // If instructions, this was mapped if ((attrInstructions != null) && (!String.IsNullOrEmpty(attrInstructions.SobekMapping))) { MappedValue thisMappedValue = new MappedValue(); thisMappedValue.Mapping = attrInstructions.SobekMapping; thisMappedValue.Path = thisPath; thisMappedValue.Path.AttributeName = attribute.Item1; thisMappedValue.Value = attribute.Item2; returnValue.MappedValues.Add(thisMappedValue); } } } } // Since this node was handled, pop it off the stack currentStack.Pop(); } } }
private void recursive_get_existing_paths(XmlReader readerXml, Stack <GenericXmlNode> currentStack, Dictionary <string, string> pathExistenceCheck, List <GenericXmlPath> returnValue) { // Create the list of nodes to this point from the stack List <GenericXmlNode> currentReverseList = currentStack.ToList(); // THis is now on THIS element, so move to the next, unless there were none if (!readerXml.Read()) { return; } // Check to see if this node has been added yet // Create the path for this GenericXmlPath currentPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { currentPath.PathNodes.Add(currentReverseList[j]); } // Was this already added? string currentPathString = currentPath.ToString(); if (!pathExistenceCheck.ContainsKey(currentPathString)) { pathExistenceCheck[currentPathString] = currentPathString; returnValue.Add(currentPath); } // First, handle any attributes if (readerXml.HasAttributes) { // Create the list of nodes to this point for (int i = 0; i < readerXml.AttributeCount; i++) { // Move to this attribute readerXml.MoveToAttribute(i); // Create the path for this GenericXmlPath thisPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { thisPath.PathNodes.Add(currentReverseList[j]); } thisPath.AttributeName = readerXml.Name; // Was this already added? string pathString = thisPath.ToString(); if (!pathExistenceCheck.ContainsKey(pathString)) { pathExistenceCheck[pathString] = pathString; returnValue.Add(thisPath); } } // Move back to the main element after handing the attributes readerXml.MoveToElement(); } //// THis is now on THIS element, so move to the next, unless there were none //if (!readerXml.Read()) return; //// Is there actual text for this element //if ( !String.IsNullOrEmpty(readerXml.Value)) //{ // // Create the path for this // GenericXmlReaderMapperPath thisPath = new GenericXmlReaderMapperPath(); // for (int j = currentReverseList.Count - 1; j >= 0; j--) // { // thisPath.PathNodes.Add(currentReverseList[j]); // } // // Was this already added? // string pathString = thisPath.ToString(); // if (!pathExistenceCheck.ContainsKey(pathString)) // { // pathExistenceCheck[pathString] = pathString; // returnValue.Add(thisPath); // } //} // Now, iterate through all the child elements that may exist while (readerXml.Read()) { if (readerXml.NodeType == XmlNodeType.Text) { // Create the path for this GenericXmlPath thisPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { thisPath.PathNodes.Add(currentReverseList[j]); } // Was this already added? string pathString = thisPath.ToString(); if (!pathExistenceCheck.ContainsKey(pathString)) { pathExistenceCheck[pathString] = pathString; returnValue.Add(thisPath); } } if (readerXml.NodeType == XmlNodeType.Element) { // Create the node for this top-level element string nodeName = readerXml.Name; GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName }; // Add this to the stack currentStack.Push(topNode); // Recursively read this and all children recursive_get_existing_paths(readerXml.ReadSubtree(), currentStack, pathExistenceCheck, returnValue); // Since this node was handled, pop it off the stack currentStack.Pop(); } } }
private void recursive_process_file(XmlReader readerXml, Stack <GenericXmlNode> currentStack, GenericXmlMappingSet set, GenericXmlReaderResults returnValue) { // Create the list of nodes to this point from the stack List <GenericXmlNode> currentReverseList = currentStack.ToList(); // THis is now on THIS element, so move to the next, unless there were none if (!readerXml.Read()) { return; } // Create the path for this GenericXmlPath currentPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { currentPath.PathNodes.Add(currentReverseList[j]); } //// First, handle any attributes //if (readerXml.HasAttributes) //{ // // Create the list of nodes to this point // for (int i = 0; i < readerXml.AttributeCount; i++) // { // // Move to this attribute // readerXml.MoveToAttribute(i); // // Create the path for this // GenericXmlPath thisPath = new GenericXmlPath(); // for (int j = currentReverseList.Count - 1; j >= 0; j--) // { // thisPath.PathNodes.Add(currentReverseList[j]); // } // thisPath.AttributeName = readerXml.Name; // // Get the value for this path // string attributeValue = readerXml.Value; // // Does mapping exist for this path? // PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath); // // If instructions, this was mapped // if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping))) // { // MappedValue thisMappedValue = new MappedValue(); // thisMappedValue.Mapping = instructions.SobekMapping; // thisMappedValue.Path = thisPath; // thisMappedValue.Value = attributeValue; // returnValue.MappedValues.Add(thisMappedValue); // } // } // // Move back to the main element after handing the attributes // readerXml.MoveToElement(); //} // Now, iterate through all the child elements that may exist while (readerXml.Read()) { //if (readerXml.NodeType == XmlNodeType.Text) //{ // // Create the path for this // GenericXmlPath thisPath = new GenericXmlPath(); // for (int j = currentReverseList.Count - 1; j >= 0; j--) // { // thisPath.PathNodes.Add(currentReverseList[j]); // } // // Does mapping exist for this path? // PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath); // // Get the value for this path // string textValue = readerXml.Value; // // If instructions, this was mapped // if ((instructions != null) && ( !String.IsNullOrEmpty(instructions.SobekMapping))) // { // MappedValue thisMappedValue = new MappedValue(); // thisMappedValue.Mapping = instructions.SobekMapping; // thisMappedValue.Path = thisPath; // thisMappedValue.Value = textValue; // returnValue.MappedValues.Add(thisMappedValue); // } //} bool text_found = false; if (readerXml.NodeType == XmlNodeType.Element) { // Create the node for this top-level element string nodeName = readerXml.Name; GenericXmlNode topNode = new GenericXmlNode { NodeName = nodeName }; // Add this to the stack currentStack.Push(topNode); if (topNode.NodeName == "text") { text_found = true; } // It may be that mapping exists right here at this level // Create the path for this currentReverseList = currentStack.ToList(); GenericXmlPath thisPath = new GenericXmlPath(); for (int j = currentReverseList.Count - 1; j >= 0; j--) { thisPath.PathNodes.Add(currentReverseList[j]); } // Does mapping exist for this path? if (set.Contains_Path(thisPath)) { // Collect the attributes FIRST List <Tuple <string, string> > attributes = null; if (readerXml.HasAttributes) { attributes = new List <Tuple <string, string> >(); readerXml.MoveToFirstAttribute(); attributes.Add(new Tuple <string, string>(readerXml.Name, readerXml.Value)); while (readerXml.MoveToNextAttribute()) { attributes.Add(new Tuple <string, string>(readerXml.Name, readerXml.Value)); } readerXml.MoveToElement(); } // Does mapping exist for this path? PathMappingInstructions instructions = set.Get_Matching_Path_Instructions(thisPath); // If instructions, this was mapped if ((instructions != null) && (!String.IsNullOrEmpty(instructions.SobekMapping)) && (instructions.IgnoreSubTree)) { MappedValue thisMappedValue = new MappedValue(); thisMappedValue.Mapping = instructions.SobekMapping; thisMappedValue.Path = thisPath; if (instructions.RetainInnerXmlTags) { thisMappedValue.Value = readerXml.ReadInnerXml(); } else { StringBuilder builder = new StringBuilder(); XmlReader innerReader = readerXml.ReadSubtree(); while (innerReader.Read()) { if (innerReader.NodeType == XmlNodeType.Text) { builder.Append(innerReader.Value); } } thisMappedValue.Value = builder.ToString(); } returnValue.MappedValues.Add(thisMappedValue); //// Actually, there is something here about skipping this //readerXml.Skip(); } else { // Recursively read this and all children recursive_process_file(readerXml.ReadSubtree(), currentStack, set, returnValue); } // Now, handle the attributes if ((attributes != null) && (attributes.Count > 0)) { foreach (Tuple <string, string> attribute in attributes) { // Does mapping exist for this path? PathMappingInstructions attrInstructions = set.Get_Matching_Path_Instructions(thisPath, attribute.Item1); // If instructions, this was mapped if ((attrInstructions != null) && (!String.IsNullOrEmpty(attrInstructions.SobekMapping))) { MappedValue thisMappedValue = new MappedValue(); thisMappedValue.Mapping = attrInstructions.SobekMapping; thisMappedValue.Path = thisPath; thisMappedValue.Path.AttributeName = attribute.Item1; thisMappedValue.Value = attribute.Item2; returnValue.MappedValues.Add(thisMappedValue); } } } } // Since this node was handled, pop it off the stack currentStack.Pop(); } } }
public PathMappingInstructions Get_Matching_Path_Instructions(GenericXmlPath Path, string AttributeName ) { if (searchNodes.Count == 0) build_search_tree(); // Look for a match if (searchNodes.ContainsKey(Path.PathNodes[0].NodeName)) { GenericXmlMappingTreeNode lastMatchingNode = searchNodes[Path.PathNodes[0].NodeName]; int index = 1; while (index < Path.PathNodes.Count) { string nextNodeName = Path.PathNodes[index].NodeName; if (!lastMatchingNode.Children.ContainsKey(nextNodeName)) return null; lastMatchingNode = lastMatchingNode.Children[nextNodeName]; index++; } // If there are instructions here, return them if ((lastMatchingNode.AttributeInstructions != null) && (lastMatchingNode.AttributeInstructions.ContainsKey(AttributeName))) return lastMatchingNode.AttributeInstructions[AttributeName]; } return null; }
public bool Contains_Path(GenericXmlPath Path) { if (searchNodes.Count == 0) build_search_tree(); // Look for a match if (searchNodes.ContainsKey(Path.PathNodes[0].NodeName)) { GenericXmlMappingTreeNode lastMatchingNode = searchNodes[Path.PathNodes[0].NodeName]; int index = 1; while (index < Path.PathNodes.Count) { string nextNodeName = Path.PathNodes[index].NodeName; if (!lastMatchingNode.Children.ContainsKey(nextNodeName)) return false; lastMatchingNode = lastMatchingNode.Children[nextNodeName]; index++; } // If there are instructions here, return them return true; } return false; }
public GenericXmlMappingPath Add_Path(GenericXmlPath Path) { GenericXmlMappingPath addPath = new GenericXmlMappingPath(Path); Mappings.Add(addPath); return addPath; }