public bool parseXMLFile(string xmlFilename)
        {
            CCSAXParser cCSAXParser = new CCSAXParser();

            if (!cCSAXParser.init("UTF-8"))
            {
                return(false);
            }
            cCSAXParser.setDelegator(this);
            return(cCSAXParser.parse(xmlFilename));
        }
Exemple #2
0
        public Dictionary <string, object> dictionaryWithContentsOfFile(string pFileName)
        {
            CCSAXParser cCSAXParser = new CCSAXParser();

            if (!cCSAXParser.init("UTF-8"))
            {
                return(null);
            }
            cCSAXParser.setDelegator(this);
            cCSAXParser.parse(pFileName);
            return(this.m_pRootDict);
        }
        public Dictionary<string, Object> dictionaryWithContentsOfFile(string pFileName)
        {
            CCSAXParser parser = new CCSAXParser();

            if (false == parser.init("UTF-8"))
            {
                return null;
            }
            parser.setDelegator(this);

            parser.parse(pFileName);
            return m_pRootDict;
        }
Exemple #4
0
        public List<Object> ArrayWithContentsOfFile(string pFileName)
        {
            CCSAXParser parser = new CCSAXParser();

            if (false == parser.Init("UTF-8"))
            {
                return null;
            }
            parser.SetDelegator(this);

            //byte[] root;

            StartElement(parser, "dict", null);
            StartElement(parser, "key", null);
            TextHandler(parser, System.Text.UTF8Encoding.UTF8.GetBytes("root"), 4);
            EndElement(parser, "key");

            parser.Parse(pFileName);

            EndElement(parser, "dict");

            return m_pRootDict["root"] as List<Object>;
        }
        /// <summary>
        /// initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file
        /// </summary>
        public bool parseXMLFile(string xmlFilename)
        {
            CCSAXParser parser = new CCSAXParser();

            if (false == parser.init("UTF-8"))
            {
                return false;
            }

            parser.setDelegator(this);

            return parser.parse(xmlFilename); ;
        }
Exemple #6
0
        public bool parse(string pszFile)
        {
#if WINDOWS_UWP
#else
            //         Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
            CCContent cCContent = CCApplication.sharedApplication().content.Load <CCContent>(pszFile);
            string    content   = cCContent.Content;
            if (cCContent == null)
            {
                return(false);
            }
            TextReader        stringReader     = new System.IO.StringReader(content);
            XmlReaderSettings xmlReaderSetting = new XmlReaderSettings()
            {
                DtdProcessing = DtdProcessing.Ignore
            };
            XmlReader xmlReader = XmlReader.Create(stringReader, xmlReaderSetting);
            int       num       = 0;
            int       num1      = 0;
            int       num2      = 0;
            while (xmlReader.Read())
            {
                string      name     = xmlReader.Name;
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element)
                {
                    string[] value = null;
                    if (name == "map")
                    {
                        num1 = ccUtils.ccParseInt(xmlReader.GetAttribute("width"));
                        num2 = ccUtils.ccParseInt(xmlReader.GetAttribute("height"));
                    }
                    if (xmlReader.HasAttributes)
                    {
                        value = new string[xmlReader.AttributeCount * 2];
                        xmlReader.MoveToFirstAttribute();
                        int num3 = 0;
                        value[0] = xmlReader.Name;
                        value[1] = xmlReader.Value;
                        num3     = num3 + 2;
                        while (xmlReader.MoveToNextAttribute())
                        {
                            value[num3]     = xmlReader.Name;
                            value[num3 + 1] = xmlReader.Value;
                            num3            = num3 + 2;
                        }
                        xmlReader.MoveToElement();
                    }
                    CCSAXParser.startElement(this, name, value);
                    byte[] bytes = null;
                    if (name == "data")
                    {
                        if (value != null)
                        {
                            string str = "";
                            for (int i = 0; i < (int)value.Length; i++)
                            {
                                if (value[i] == "encoding")
                                {
                                    str = value[i + 1];
                                }
                            }
                            if (str != "base64")
                            {
                                string str1 = xmlReader.ReadElementContentAsString();
                                bytes = Encoding.UTF8.GetBytes(str1);
                            }
                            else
                            {
                                int num4 = num1 * num2 * 4 + 1024;
                                bytes = new byte[num4];
                                xmlReader.ReadElementContentAsBase64(bytes, 0, num4);
                            }
                        }
                        CCSAXParser.textHandler(this, bytes, (int)bytes.Length);
                        CCSAXParser.endElement(this, name);
                    }
                    else if (name == "key" || name == "integer" || name == "real" || name == "string" || name == "true" || name == "false")
                    {
                        string str2 = xmlReader.ReadElementContentAsString();
                        bytes = Encoding.UTF8.GetBytes(str2);
                        CCSAXParser.textHandler(this, bytes, (int)bytes.Length);
                        CCSAXParser.endElement(this, name);
                    }
                    else
                    {
                        IXmlLineInfo xmlLineInfo = (IXmlLineInfo)xmlReader;
                        object[]     lineNumber  = new object[] { "Failed to handle XML tag: ", name, " in ", xmlLineInfo.LineNumber, "@", xmlLineInfo.LinePosition, ":", pszFile };
                        CCLog.Log(string.Concat(lineNumber));
                    }
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    CCSAXParser.endElement(this, xmlReader.Name);
                    num++;
                }
            }
            return(true);
        }
Exemple #7
0
        public bool ParseXmlString(string data)
        {
            var parser = new CCSAXParser();

            if (false == parser.Init("UTF-8"))
            {
                return false;
            }

            parser.SetDelegator(this);

            return parser.Parse(data, data.Length);
        }
Exemple #8
0
        /// <summary>
        /// initalises parsing of an XML file, either a tmx (Map) file or tsx (Tileset) file
        /// </summary>
        public bool ParseXmlFile(string xmlFilename)
        {
            var parser = new CCSAXParser();

            if (false == parser.Init("UTF-8"))
            {
                return false;
            }

            parser.SetDelegator(this);

            return parser.Parse(xmlFilename);
        }