Пример #1
0
        //returns 1 on success, 0 on failed
        public int Parse()
        {
            if (reader == null)
            {
                return(0);
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    string strElementName  = reader.Name;
                    string strNamespaceURI = reader.NamespaceURI;
                    attr[] attrs           = new attr[reader.AttributeCount];
                    if (reader.HasAttributes)
                    {
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            attr na = new attr();
                            na.attrName = reader.Name;
                            na.attrVal  = reader.Value;
                            attrs[i]    = na;
                        }
                    }
                    if (OnElementStart != null)
                    {
                        OnElementStart(strElementName, strNamespaceURI, reader.AttributeCount, attrs);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (OnElementEnd != null)
                    {
                        OnElementEnd(reader.Name);
                    }
                    break;

                case XmlNodeType.Text:
                    if (OnElementData != null)
                    {
                        OnElementData(reader.Name, reader.Value);
                    }
                    break;
                }
            }
            return(1);
        }
Пример #2
0
        //returns 1 on success, 0 on failed
        public int Parse()
        {
            if (reader == null) return 0;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        string strElementName = reader.Name;
                        string strNamespaceURI = reader.NamespaceURI;
                        attr[] attrs = new attr[reader.AttributeCount];
                        if (reader.HasAttributes)
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                attr na = new attr();
                                na.attrName = reader.Name;
                                na.attrVal = reader.Value;
                                attrs[i] = na;
                            }
                        }
                        if (OnElementStart != null )
                        {
                            OnElementStart(strElementName, strNamespaceURI, reader.AttributeCount, attrs);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (OnElementEnd != null)
                        {
                            OnElementEnd(reader.Name);
                        }
                        break;

                    case XmlNodeType.Text:
                        if (OnElementData != null)
                        {
                            OnElementData(reader.Name, reader.Value);
                        }
                        break;
                }
            }
            return 1;
        }