Beispiel #1
0
        public void startElement(string nodeName, List <XML_Attribute> attributes)
        {
            XML_SaxParserComponent lastComponent = _components[_components.Count - 1];
            XML_SaxParserComponent newComponent  = lastComponent.startElement(nodeName, attributes);

            if (lastComponent != newComponent)
            {
                newComponent.startComponent();
            }

            _components.Add(newComponent);
        }
Beispiel #2
0
        public static void parseXmlFile(string filename, XML_SaxParserComponent mainComponent)
        {
            XML_SaxParserDelegator delegator = new XML_SaxParserDelegator(mainComponent);

            XmlTextReader reader = new XmlTextReader(filename);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element: // The node is an element.

                    List <XML_Attribute> attributes = new List <XML_Attribute>();

                    if (reader.HasAttributes)
                    {
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);

                            XML_Attribute attribute = new XML_Attribute();
                            attribute._name  = reader.Name;
                            attribute._value = reader.Value;

                            attributes.Add(attribute);
                        }
                        reader.MoveToElement(); //Moves the reader back to the element node.
                    }

                    if (reader.IsEmptyElement)
                    {
                        delegator.startElement(reader.Name, attributes);
                        delegator.endElement(reader.Name);
                    }
                    else
                    {
                        delegator.startElement(reader.Name, attributes);
                    }

                    break;

                case XmlNodeType.Text: //Display the text in each element.
                    //Debug.LogWarning(reader.Value);
                    break;

                case XmlNodeType.EndElement: //Display the end of the element.

                    delegator.endElement(reader.Name);
                    break;
                }
            }
        }
Beispiel #3
0
        public void endElement(string nodeName)
        {
            XML_SaxParserComponent lastComponent = _components[_components.Count - 1];

            lastComponent.endElement(nodeName);

            _components.RemoveAt(_components.Count - 1);

            if ((_components.Count == 0) || (lastComponent != _components[_components.Count - 1]))
            {
                lastComponent.endComponent();
            }
        }
Beispiel #4
0
 public XML_SaxParserDelegator(XML_SaxParserComponent component)
 {
     _components = new List <XML_SaxParserComponent>();
     _components.Add(component);
 }