예제 #1
0
 public OldParserSynchronizer(EnhancedXmlParser enhancedXmlParser, IXmlTagParsingStrategy parsingStrategy, XmlParser oldParser)
 {
     this.enhancedXmlParser = enhancedXmlParser;
     this.oldParser         = oldParser;
     this.parsingStrategy   = parsingStrategy;
     enhancedXmlParser.MoveOldParserToCurrentTag(oldParser);
 }
예제 #2
0
        /// <summary>
        /// remove the specified elements from the XML buffer
        /// </summary>
        /// <param name="xmlBuffer">The XML buffer to change</param>
        /// <param name="elementTagsToRemove">Array of strings (=element tags) to remove from the buffer</param>
        /// <returns></returns>
        public static String RemoveXmlElements(String xmlBuffer, params string[] elementTagsToRemove)
        {
            EnhancedXmlParser parser = new EnhancedXmlParser();

            // Go over all tags to be removed
            foreach (String tagToRemove in elementTagsToRemove)
            {
                StringBuilder returnedXml = new StringBuilder();
                parser.SetXMLData(xmlBuffer);
                int startIndex = 0;

                // loop while the requested tag exists in the XML buffer
                while (parser.MoveToElement(tagToRemove))
                {
                    // read the string up to the tag
                    returnedXml.Append(xmlBuffer.Substring(startIndex, parser.CurrentPosition - startIndex));

                    // skip the element using the parser to find the end of the tag
                    parser.ReadToEndOfCurrentElement();
                    startIndex = parser.CurrentPosition;
                }

                // add what remained after the last removed tag
                returnedXml.Append(xmlBuffer.Substring(startIndex));
                //prepare the buffer for the next tag to remove
                xmlBuffer = returnedXml.ToString();
            }
            return(xmlBuffer);
        }
예제 #3
0
        public bool Deserialize(EnhancedXmlParser parser)
        {
            using (parser.ElementBoundary())
            {
                if (!EnterElement(parser))
                {
                    return(false);
                }

                while (parser.MoveToNextTag(GetTagParsingStrategy()))
                {
                    if (!parser.IsOnElementClosingTag)
                    {
                        if (!ProcessInnerElement(parser))
                        {
                            Logger.Instance.WriteErrorToLog("An error occurred while deserializing an object. See previous messages for more details.");
                            return(false);
                        }
                    }
                }

                if (!LeaveElement(parser))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #4
0
 public ParserContextSwitch(EnhancedXmlParser parser)
 {
     this.parser = parser;
 }
예제 #5
0
 protected virtual bool ProcessInnerElement(EnhancedXmlParser parser)
 {
     return(true);
 }
예제 #6
0
 protected virtual bool LeaveElement(EnhancedXmlParser parser)
 {
     return(true);
 }