示例#1
0
    private static SpawnPoint parseSpawnPoint(XMLNode node)
    {
        SpawnPoint result;

        result = new SpawnPoint((float.Parse(node.attributes["x"]) + 8f), -(float.Parse(node.attributes["y"]) - 8f));
        return result;
    }
示例#2
0
 public static void PrintNode(int recnum, XMLNode node)
 {
     Console.WriteLine(new String(' ', recnum) + "Type: " + node.Type +
         "  Value: " + node.Value);
     if (node.Child != null) PrintNode(recnum + 1, node.Child);
     if (node.Next != null) PrintNode(recnum, node.Next);
 }
示例#3
0
    // fill a multilanguages object from languages detected from an XMLNode
    public static void FillLanguages(MultiLanguages multiLang, XMLNode node)
    {
        XMLNodeList names = node.GetNodeList ("nom>0>text");

        foreach (XMLNode name in names)
        {
            string lang = name.GetValue ("@lang");
            string text = name.GetValue ("_text");

            string defaultAtt = name.GetValue ("@defaut");
            bool isDefault;
            bool.TryParse (defaultAtt, out isDefault);

            multiLang.AddText (lang, text, isDefault);
        }

        XMLNodeList parent = node.GetNodeList ("parent>0>text");

        foreach (XMLNode name in parent)
        {
            string lang = name.GetValue ("@lang");
            string text = name.GetValue ("_text");

            string defaultAtt = name.GetValue ("@defaut");
            bool isDefault;
            bool.TryParse (defaultAtt, out isDefault);

            //Debug.Log (text);
            multiLang.AddText (lang + "_parent", text, isDefault);
        }
    }
示例#4
0
文件: XMLReader.cs 项目: Morac/Orca6
 public XMLNode()
 {
     tagName = "NONE";
     parentNode = null;
     children = new ArrayList();
     attributes = new Dictionary<String, String>();
     values = new List<XMLValue>();
 }
示例#5
0
    public static void Main(string[] args)
    {
        if (args.Length != 1) usage();

        XMLNode node = new XMLNode(args[0]);

        PrintNode(0, node);
    }
示例#6
0
    public void CheckIkey()
    {
        n = (new XMLNode("tasks","") )
            .AddAttribute("ikey","an_ikey")
            ;
        Hashtable h = ee.BuildHashtable(n);

        Assert.AreEqual( "an_ikey", h["ikey"] );
    }
示例#7
0
 public void CheckCostParserGetsNodeNames()
 {
     n = (new XMLNode("costs","") )
         .AddChild( (new XMLNode("cost_a","")) )
         .AddChild( (new XMLNode("cost_b","")) );
     ArrayList costs = (new DC.CRMParser()).ParseCostList(n);
     Assert.AreEqual(2, costs.Count );
     Assert.AreEqual("cost_a", ((Hashtable)costs[0])["name"] );
     Assert.AreEqual("cost_b", ((Hashtable)costs[1])["name"] );
 }
示例#8
0
    public XMLNode Pop()
    {
        XMLNode item = null;

        if (this.Count > 0)
        {
            item = (XMLNode)this[this.Count - 1];
            this.Remove(item);
        }

        return(item);
    }
示例#9
0
        public void Read()
        {
            string  fileNameInZip = string.Format("xl/worksheets/sheet{0}.xml", Index);
            XMLNode document      = m_Excel.m_Archive.GetXmlNode(fileNameInZip);

            if (document != null)
            {
                XMLNodeList rowList = document.GetNodeList("worksheet>0>sheetData>0>row");
                Rows          = GetRows(rowList);
                this.RowCount = Rows.Count;
            }
        }
示例#10
0
        //剧情加载回调
        private void ScriptLoaded(TextAsset textObj)
        {
            try
            {
                if (!scriptDict.ContainsKey(curScriptEntry.ScriptName))
                {
                    if (null != textObj)
                    {
                        scriptDict.Add(curScriptEntry.ScriptName, textObj);
                    }
                }

                //判断文件是否存在
                if (!scriptDict.ContainsKey(curScriptEntry.ScriptName))
                {
                    return;
                }

                if (null != AppMap.Instance.me.Controller.GoName)
                {
                    roleGoActive = AppMap.Instance.me.Controller.GoName.activeSelf;
                }

                //解析剧情数据
                string actionName = "script>0>action";

                XMLNode rootNode = XMLParser.Parse(scriptDict[curScriptEntry.ScriptName].ToString());
                if (null != rootNode)
                {
                    foreach (XMLNode actionNode in rootNode.GetNodeList(actionName))
                    {
                        string type = actionNode.GetValue("@type");

                        BaseAction baseAction = StoryFactory.GetAction(type);
                        if (null != baseAction)
                        {
                            baseAction.ParseNode(actionNode);
                            actionList.Add(baseAction);
                        }
                    }
                }
            }
            finally
            {
                loadingData = false;

                if (null != loadActionDataCallback)
                {
                    loadActionDataCallback();
                }
            }
        }
示例#11
0
    private object GetObject(string path)
    {
        string[]    bits            = path.Split('>');
        XMLNode     currentNode     = this;
        XMLNodeList currentNodeList = null;
        bool        listMode        = false;
        object      ob;

        for (int i = 0; i < bits.Length; i++)
        {
            if (listMode)
            {
                currentNode = (XMLNode)currentNodeList[int.Parse(bits[i])];
                ob          = currentNode;
                listMode    = false;
            }
            else
            {
                ob = currentNode[bits[i]];

                if (ob is ArrayList)
                {
                    currentNodeList = (XMLNodeList)(ob as ArrayList);
                    listMode        = true;
                }
                else
                {
                    // reached a leaf node/attribute
                    if (i != (bits.Length - 1))
                    {
                        // unexpected leaf node
                        string actualPath = "";
                        for (int j = 0; j <= i; j++)
                        {
                            actualPath = actualPath + ">" + bits[j];
                        }
                    }

                    return(ob);
                }
            }
        }

        if (listMode)
        {
            return(currentNodeList);
        }
        else
        {
            return(currentNode);
        }
    }
示例#12
0
        public override void ParseNode(XMLNode node)
        {
            this.createId = node.GetValue("@id");
            this.targetX  = Convert.ToSingle(node.GetValue("@targetX"));
            this.targetY  = Convert.ToSingle(node.GetValue("@targetY"));
            this.speed    = Convert.ToInt32(node.GetValue("@speed"));
            this.block    = Convert.ToBoolean(node.GetValue("@block"));

            if (this.speed <= 0f)
            {
                speed = Global.ROLE_RUN_SPEED;
            }
        }
示例#13
0
    public XMLNode Parse(string xml)
    {
        xml = xml.Replace("&amp;", "&");
        xml = xml.Replace("&nbsp;", " ");
        xml = xml.Replace(" <br> ", "\n");
        xml = xml.Replace(" <br/> ", "\n");
        xml = xml.Replace("<br>", "\n");
        xml = xml.Replace("<br/>", "\n");

        XMLNode xmlNode = XMLParser.Parse(xml);

        return(xmlNode);
    }
示例#14
0
文件: NPC.cs 项目: NerdDev/Hackmobile
 public override void ParseXML(XMLNode x)
 {
     base.ParseXML(x);
     Attributes    = x.Select <AttributesData>("attributes");
     Stats         = x.Select <Stats>("stats");
     Flags         = new GenericFlags <NPCFlags>(x.SelectEnums <NPCFlags>("flags"));
     SpawnKeywords = new GenericFlags <SpawnKeywords>(x.SelectEnums <SpawnKeywords>("spawnkeywords"));
     KnownSpells   = x.Select <Spells>("spells");
     StartingItems = x.Select <StartingItems>("startingitems");
     Equipment     = x.Select <Equipment>("equipslots");
     NaturalWeapon = x.Select <Item>("naturalweapon");
     //parse AI packages
 }
示例#15
0
    public void ParseXML(XMLNode spell)
    {
        range = spell.SelectInt("range");
        cost  = spell.SelectInt("cost");
        // If no targeter specified, assume self
        AddAspect(new Self(), GetEffects(spell.SelectList("effect")));

        foreach (XMLNode targeter in spell.SelectList("targeter"))
        {
            string targeterType = targeter.SelectString("type");
            AddAspect(BigBoss.Types.Instantiate <ITargeter>(targeterType), GetEffects(targeter.SelectList("effect")));
        }
    }
示例#16
0
 //---------------------------------------------------------------------------------
 // Start
 //---------------------------------------------------------------------------------
 public XMLInStream Start(string tag)
 {
     foreach (XMLNode child in current.children)
     {
         if (child.tag == tag)
         {
             current = child;
             return(this);
         }
     }
     Debug.LogError("No child node named: " + tag + " in node " + current.tag);
     return(null);
 }
示例#17
0
 public static void PrintNode(int recnum, XMLNode node)
 {
     Console.WriteLine(new String(' ', recnum) + "Type: " + node.Type +
                       "  Value: " + node.Value);
     if (node.Child != null)
     {
         PrintNode(recnum + 1, node.Child);
     }
     if (node.Next != null)
     {
         PrintNode(recnum, node.Next);
     }
 }
示例#18
0
        public void test_XMLNode_addChild3()
        {
            XMLTriple triple = new  XMLTriple("test", "", "");
            XMLNode   node   = new XMLNode(triple);
            XMLNode   node2  = new XMLNode();
            int       i      = node.addChild(node2);

            assertTrue(i == libsbml.LIBSBML_INVALID_XML_OPERATION);
            assertTrue(node.getNumChildren() == 0);
            triple = null;
            node   = null;
            node2  = null;
        }
示例#19
0
    /// <summary>
    /// 设置渠道信息
    /// </summary>
    /// <param name="xmlNodeList"></param>
    static void SetChannelInfo(XMLNode rootnode)
    {
        if (rootnode == null)
        {
            return;
        }

        XMLNodeList xmlNodeList = rootnode.GetNodeList("Resources>0>Channel>0>Property");

        GameArea = EnumArea.None;

        if (string.IsNullOrEmpty(strChannelUniqueName))
        {
#if UNITY_IPHONE
            strChannelUniqueName = "appstore";
#else
            strChannelUniqueName = "android_snail";
#endif
        }

        ///解析首段中的类型定义
        foreach (XMLNode n in xmlNodeList)
        {
            string strID = n.GetValue("@ID");
            if (strID == strChannelUniqueName)
            {
                payCallBackURL   = n.GetValue("@PayCallBackUrl");
                ClientInstallUrl = n.GetValue("@ClientInstallUrl");
                strNoticeName    = n.GetValue("@NoticeName");
                strChannelName   = n.GetValue("@ChannelName");
                mOrderType       = StaticUtilTools.IntParse(n.GetValue("@OrderType"));
                //采集
                bNeedDataCollect = "1".Equals(n.GetValue("@DataCollect"));
#if UNITY_STANDALONE_OSX && !UNITY_EDITOR
                bNeedDataCollect = true;
#endif
                //地区
                string strArea = n.GetValue("@Area");
                if (!string.IsNullOrEmpty(strArea))
                {
                    int iArea;
                    if (int.TryParse(strArea, out iArea))
                    {
                        GameArea = (EnumArea)iArea;
                    }
                }
                return;
            }
        }
        LogSystem.LogWarning("channelName not have info ", strChannelUniqueName);
    }
示例#20
0
 private static void SetCustomInfo(XMLNodeList xmlNodeList)
 {
     if (xmlNodeList == null)
     {
         LogSystem.LogWarning(new object[]
         {
             "SetCustomInfo is null"
         });
         return;
     }
     for (int i = 0; i < xmlNodeList.Count; i++)
     {
         XMLNode     xMLNode  = xmlNodeList[i] as XMLNode;
         XMLNodeList nodeList = xMLNode.GetNodeList("Resource");
         if (nodeList != null)
         {
             for (int j = 0; j < nodeList.Count; j++)
             {
                 XMLNode           xMLNode2   = nodeList[j] as XMLNode;
                 Config.CustomInfo customInfo = new Config.CustomInfo();
                 foreach (DictionaryEntry dictionaryEntry in xMLNode2)
                 {
                     if (dictionaryEntry.Value != null)
                     {
                         string text = dictionaryEntry.Key as string;
                         if (text[0] == '@')
                         {
                             text = text.Substring(1);
                             if (text == "ID")
                             {
                                 customInfo.strCustomInfoID = (dictionaryEntry.Value as string);
                             }
                             else if (text == "Value")
                             {
                                 customInfo.strCustomInfoVaule = (dictionaryEntry.Value as string);
                             }
                         }
                     }
                 }
                 if (Config.mDictCustomInfoList.ContainsKey(customInfo.strCustomInfoID))
                 {
                     Config.mDictCustomInfoList[customInfo.strCustomInfoID] = customInfo;
                 }
                 else
                 {
                     Config.mDictCustomInfoList.Add(customInfo.strCustomInfoID, customInfo);
                 }
             }
         }
     }
 }
示例#21
0
        private void loadSocketTip()
        {
            //TextAsset tepXML = (TextAsset)ResMgr.instance.load("xml/socket");
            //XmlDocument doc = InitConfig.loadXMLByContent(tepXML.ToString());
            //XmlNodeList nodeList = doc.SelectSingleNode("i18n").ChildNodes;
            //parserMsgList(socketDict, nodeList);

            TextAsset   tepXML   = (TextAsset)ResMgr.instance.load("xml/socket");
            XMLNode     rootNode = XMLParser.Parse(tepXML.ToString());
            XMLNodeList nodeList = rootNode.GetNodeList("i18n>0>tip");

            //Debug.Log("nodeList.length:"+nodeList.Count);
            parserMsgList(socketDict, nodeList);
        }
示例#22
0
        public void test_XMLNode_equals()
        {
            string  xmlstr = "<annotation>\n" + "  <test xmlns=\"http://test.org/\" id=\"test\">test</test>\n" + "</annotation>";
            XMLNode node   = new XMLNode();
            XMLNode node1  = XMLNode.convertStringToXMLNode(xmlstr, null);

            assertEquals(false, node.equals(node1));
            node = null;
            XMLNode node2 = XMLNode.convertStringToXMLNode(xmlstr, null);

            assertEquals(true, node2.equals(node1));
            node1 = null;
            node2 = null;
        }
示例#23
0
    private object GetObject(string path)
    {
        XMLNode     currentNode     = this;
        XMLNodeList currentNodeList = null;
        bool        listMode        = false;

        string[] array = path.Split(new char[]
        {
            '>'
        });
        object result;

        for (int i = 0; i < array.Length; i++)
        {
            if (listMode)
            {
                currentNode = (currentNodeList[int.Parse(array[i])] as XMLNode);
                listMode    = false;
            }
            else
            {
                object obj = currentNode[array[i]];

                if (!(obj is XMLNodeList))
                {
                    // reached a leaf node/attribute
                    if (i != array.Length - 1)
                    {
                        string actualPath = "";
                        for (int j = 0; j <= i; j++)
                        {
                            actualPath = actualPath + ">" + array[j];
                        }
                        UnityEngine.Debug.Log("xml path search truncated. Wanted: " + path + " got: " + actualPath);
                    }
                    result = obj;
                    return(result);
                }
                currentNodeList = (obj as XMLNodeList);
                listMode        = true;
            }
        }
        if (listMode)
        {
            result = currentNodeList;
            return(result);
        }
        result = currentNode;
        return(result);
    }
示例#24
0
        public override void ParseNode(XMLNode node)
        {
            base.ParseNode(node);

            foreach (XMLNode conditionNode in node.GetNodeList(StoryConst.CONDITION_NAME))
            {
                string monsterId = conditionNode.GetValue("@monsterId");

                if (null != monsterId)
                {
                    this.MonsterId = monsterId;
                }
            }
        }
 public void test_RDFAnnotation_deleteWithOutOther()
 {
   Compartment c = m.getCompartment(2);
   XMLNode node = c.getAnnotation();
   string expected = "<annotation>\n" + "  <jd2:JDesignerLayout version=\"2.0\" MajorVersion=\"2\" MinorVersion=\"0\" BuildVersion=\"41\">\n" + 
 "    <jd2:header>\n" + 
 "      <jd2:VersionHeader JDesignerVersion=\"2.0\"/>\n" + 
 "      <jd2:ModelHeader Author=\"Mr Untitled\" ModelVersion=\"0.0\" ModelTitle=\"untitled\"/>\n" + 
 "      <jd2:TimeCourseDetails timeStart=\"0\" timeEnd=\"10\" numberOfPoints=\"1000\"/>\n" + 
 "    </jd2:header>\n" + 
 "  </jd2:JDesignerLayout>\n" + 
 "</annotation>";
   assertEquals( true, equals(expected,node.toXMLString()) );
 }
示例#26
0
        public void test_XMLNode_getChildForName()
        {
            string  xmlstr     = "<annotation>\n" + "  <test xmlns=\"http://test.org/\" id=\"test\">test</test>\n" + "</annotation>";
            XMLNode node       = new XMLNode();
            XMLNode annotation = node.getChild("test");
            string  name       = annotation.getName();

            assertTrue(name == "");
            node       = null;
            node       = XMLNode.convertStringToXMLNode(xmlstr, null);
            annotation = node.getChild("test");
            assertTrue(("test" != annotation.getName()) == false);
            node = null;
        }
示例#27
0
        private void LoadRandomNameCallback(TextAsset nameText)
        {
            string text = nameText.ToString();

/*            text = text.Replace("\r\n", "").Replace("\t", "");
 *          int sin, dou, nam;
 *          string douStr, namStr;
 *          sin = text.IndexOf("//单姓");
 *          dou = text.IndexOf("//复姓");
 *          nam = text.IndexOf("//名字");
 *          singleFamilys = text.Substring(sin + 4, dou - sin - 4);
 *          douStr = text.Substring(dou + 4, nam - dou - 4);
 *          namStr = text.Substring(nam + 4);
 *          //sinStr=sinStr.Replace("\"", "").Replace(" +", "");
 *          //douStr=douStr.Replace("[\"","").Replace("\"];","");
 *          //namStr = namStr.Replace("[\"", "").Replace("\"];", "");
 *          //doubleFamilys = Regex.Split(douStr, "\",\"", RegexOptions.IgnoreCase);
 *          //firstNames = Regex.Split(namStr, "\",\"", RegexOptions.IgnoreCase);
 *
 *          douStr = douStr.Replace("\",\"", "|");
 *          douStr = douStr.Replace("\"", "");
 *          doubleFamilys = douStr.Split('|');
 *
 *          namStr = namStr.Replace("\",\"", "|");
 *          namStr = namStr.Replace("\"", "");
 *          firstNames = namStr.Split('|');*/

            XMLNode xml  = XMLParser.Parse(text);
            string  spec = xml.GetValue("root>0>special>0>_text");

            _specialName = spec.Split(',');

            string manS = xml.GetValue("root>0>man>0>single>0>_text");

            _manSingleName = manS.Split(',');

            string manD = xml.GetValue("root>0>man>0>double>0>_text");

            _manDoubleName = manD.Split(',');

            string womanS = xml.GetValue("root>0>women>0>single>0>_text");

            _womanSingleName = womanS.Split(',');

            string womanD = xml.GetValue("root>0>women>0>double>0>_text");

            _womanDoubleName = womanD.Split(',');

            RandomRole(null);
        }
示例#28
0
 //---------------------------------------------------------------------------------
 // Start
 //---------------------------------------------------------------------------------
 public XMLOutStream Start(string tag)
 {
     if (current == null)
     {
         current = new XMLNode(tag);
     }
     else
     {
         XMLNode child = new XMLNode(tag);
         current.AddChild(child);
         current = child;
     }
     return(this);
 }
示例#29
0
    public void FromXML(XMLNode xml)
    {
        if (xml == null)
        {
            return;
        }

        //GameObject animationObjectGO = GameObject.Find(xml["animationObject"].FirstChild.Value);
        //if (animationObjectGO != null)
        //    animationObject = animationObjectGO.transform;


        //GameObject orientationTargetGO = GameObject.Find(xml["orientationTarget"].FirstChild.Value);
        //if (orientationTargetGO != null)
        //    orientationTarget = orientationTargetGO.transform;

        //_animateSceneObjectInEditor = bool.Parse(xml["animateSceneObjectInEditor"].FirstChild.Value);
        //playOnStart = bool.Parse(xml["playOnStart"].FirstChild.Value);

        //animationMode = (animationModes)Enum.Parse(typeof(animationModes), xml["animationMode"].FirstChild.Value);
        //orientationMode = (orientationModes)Enum.Parse(typeof(orientationModes), xml["orientationMode"].FirstChild.Value);

        //normalised = bool.Parse(xml["normalised"].FirstChild.Value);
        //_pathSpeed = float.Parse(xml["pathSpeed"].FirstChild.Value);


        GameObject animationObjectGO = GameObject.Find(xml.GetValue("animationObject>0>_text"));

        if (animationObjectGO != null)
        {
            animationObject = animationObjectGO.transform;
        }


        GameObject orientationTargetGO = GameObject.Find(xml.GetValue("orientationTarget>0>_text"));

        if (orientationTargetGO != null)
        {
            orientationTarget = orientationTargetGO.transform;
        }

        _animateSceneObjectInEditor = bool.Parse(xml.GetValue("animateSceneObjectInEditor>0>_text"));
        playOnStart = bool.Parse(xml.GetValue("playOnStart>0>_text"));

        animationMode   = (animationModes)Enum.Parse(typeof(animationModes), xml.GetValue("animationMode>0>_text"));
        orientationMode = (orientationModes)Enum.Parse(typeof(orientationModes), xml.GetValue("orientationMode>0>_text"));

        normalised = bool.Parse(xml.GetValue("normalised>0>_text"));
        _pathSpeed = float.Parse(xml.GetValue("pathSpeed>0>_text"));
    }
示例#30
0
    // GetNodeString
    #endregion

    #region GetNestedNodeString

    /// <summary>
    /// Get the string value from the xml node
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="key"></param>
    /// <param name="nodeChild"></param>
    /// <param name="nodeRoot"></param>
    /// <returns></returns>
    private string GetNestedNodeString(XMLNode xmlNode, string nodeRoot, string nodeChild, string key)
    {
        // exit if no nested node
        if (xmlNode.GetNode(nodeRoot) == null)
        {
            return(null);
        }

        XMLNode tempNode = xmlNode.GetNode(nodeRoot).GetNode(nodeChild);

        return(((tempNode != null) && (tempNode.ContainsKey(key))) ?
               tempNode[key].ToString() :
               null);
    }
示例#31
0
    // CreateSlider
    #endregion

    #region CreateProgressbar

    /// <summary>
    /// Creates a progressbar
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static void CreateProgressbar(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject NewGO = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // add the slider to the parent
        UIProgressBar ProgressGO = NewGO.AddComponent <UIProgressBar>();

        // add a sprite to the parent
        UISprite BackgroundSprite = AddSpriteToGo(NewGO, psdAssetFolderPath, WidgetInfo.Background, targetRootPanel, WidgetInfo.PosX, WidgetInfo.PosY, targetWidth, targetHeight);

        // fail if nothing returned
        if (BackgroundSprite == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.Background));
            return;
        }

        // add the box collider
        NGUITools.AddWidgetCollider(NewGO);


        // create the foreground child object
        UISprite ForegroundChild = CreateChildSprite(
            NewGO,
            string.Format("{0} - Foreground", WidgetInfo.Name),
            psdAssetFolderPath,
            WidgetInfo.Foreground,
            targetRootPanel,
            WidgetInfo.PosX,
            WidgetInfo.PosY,
            targetWidth,
            targetHeight);

        // fail if nothing returned
        if (ForegroundChild == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.Foreground));
            return;
        }


        // set slider properties
        ProgressGO.backgroundWidget = BackgroundSprite;
        ProgressGO.foregroundWidget = ForegroundChild;
    }
示例#32
0
    private object GetObject(string path)
    {
        string[] array = path.Split(new char[]
        {
            '>'
        });
        XMLNode     xMLNode     = this;
        XMLNodeList xMLNodeList = null;
        bool        flag        = false;

        for (int i = 0; i < array.Length; i++)
        {
            if (flag)
            {
                xMLNode = (XMLNode)xMLNodeList[int.Parse(array[i])];
                flag    = false;
            }
            else
            {
                object obj = xMLNode[array[i]];
                if (obj is ArrayList)
                {
                    xMLNodeList = (XMLNodeList)(obj as ArrayList);
                    flag        = true;
                }
                else
                {
                    if (i != array.Length - 1)
                    {
                        string str = string.Empty;
                        for (int j = 0; j <= i; j++)
                        {
                            str = str + ">" + array[j];
                        }
                    }
                    if (obj == null)
                    {
                        return(string.Empty);
                    }
                    return(obj);
                }
            }
        }
        if (flag)
        {
            return(xMLNodeList);
        }
        return(xMLNode);
    }
示例#33
0
 public override void Parse(XMLNode itemsNode)
 {
     foreach (XMLNode categoryNode in itemsNode)
     {
         foreach (XMLNode itemNode in categoryNode)
         {
             Item i = new Item();
             i.ParseXML(itemNode);
             if (!Add(i, categoryNode.Key) && BigBoss.Debug.logging(Logs.XML))
             {
                 BigBoss.Debug.w(Logs.XML, "Item already existed with name: " + i.Name + " under node " + itemNode);
             }
         }
     }
 }
示例#34
0
    protected void importXML(string text)
    {
        XMLReader xmlReader = new XMLReader();
        XMLNode   root      = xmlReader.read(text).children[0] as XMLNode;

        foreach (XMLNode record in root.children)
        {
            Dictionary <string, string> items = new Dictionary <string, string>();
            foreach (XMLNode item in record.children)
            {
                items.Add(item.tagName, item.cdata);
            }
            strings.Add(record.attributes["id"], items);
        }
    }
示例#35
0
 private void DevelopInit()
 {
     // 读取配置文件
     try
     {
         string    content = File.ReadAllText(this.SHARE_PATH + @"\Pfmd\config.xml", Encoding.UTF8);
         XMLParser xp      = new XMLParser();
         XMLNode   xn      = xp.Parse(content);
         this.URL_HEAD = xn.GetValue("Config>0>@UrlHead");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#36
0
    // CreateTextLabel
    #endregion

    #region CreateInputLabel

    /// <summary>
    /// Creates an input label
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static void CreateInputLabel(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // create the label
        GameObject LabelGO  = CreateTextLabel(xmlNode, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput, targetWidth, targetHeight, psdAssetFolderPath);
        UILabel    TheLabel = LabelGO.GetComponent <UILabel>();

        // add input
        UIInput NewInputLabel = LabelGO.AddComponent <UIInput>();

        NewInputLabel.label           = TheLabel;
        NewInputLabel.activeTextColor = TheLabel.color;

        // add the box collider
        NGUITools.AddWidgetCollider(LabelGO);
    }
示例#37
0
    private void ParseXML(string file)
    {
        XMLNode root = new XMLNode(null); // No parent

        root.Parse(file);

        #region DEBUG
        if (BigBoss.Debug.Flag(DebugManager.DebugFlag.XML_Print) && BigBoss.Debug.logging(Logs.XML))
        {
            BigBoss.Debug.w(Logs.XML, root.Print());
        }
        #endregion

        ParseXML(root);
    }
示例#38
0
文件: XMLReader.cs 项目: Morac/Orca6
    public XMLNode parseAttributes(String xmlTag, XMLNode node)
    {
        int index = 0;
        int attrNameIndex = 0;
        int lastIndex = 0;

        while ( true )
        {
            index = xmlTag.IndexOf(BEGIN_QUOTE, lastIndex);
            if ( index < 0 || index > xmlTag.Length )
            {
                break;
            }

            attrNameIndex = xmlTag.LastIndexOf(SPACE, index);
            if ( attrNameIndex < 0 || attrNameIndex > xmlTag.Length )
            {
                break;
            }

            attrNameIndex++;
            String attrName = xmlTag.Substring(attrNameIndex, index - attrNameIndex);

            // skip the equal and quote character
            //
            index += 2;

            lastIndex = xmlTag.IndexOf(QUOTE, index);
            if ( lastIndex < 0 || lastIndex > xmlTag.Length )
            {
                break;
            }

            int tagLength = lastIndex - index;
            String attrValue = xmlTag.Substring(index, tagLength);

            node.attributes[attrName] = attrValue;

            XMLValue val = new XMLValue();
            val.name = attrName;
            val.value = attrValue;
            node.values.Add(val);
        }

        return node;
    }
示例#39
0
    public void CheckCRMParserCalledForCosts()
    {
        n = (new XMLNode("tasks","") )
            .AddAttribute("ikey","an_ikey")
            .AddChild(
                (new XMLNode("costs",""))
                    .AddChild( new XMLNode("cost_a","") )
                    .AddChild( new XMLNode("cost_b","") )
             );

        ArrayList cost_list = new ArrayList();
        ee.CrmParser_ = mocks.NewMock<DC.ICRMParser>();
        Expect.Once.On(ee.CrmParser_)
            .Method("ParseCostList")
            .With( n.GetFirstChild("costs") )
            .Will(Return.Value( cost_list ) );

        Hashtable h = ee.BuildHashtable(n);
        Assert.AreSame( cost_list, h["costs"] );
    }
示例#40
0
    private static ArrowTurret parseArrowTurret(XMLNode node, World world)
    {
        float interval = 1;
        float initdelay = 0;
        FutileFourDirectionBaseObject.Direction turretDirection = FutileFourDirectionBaseObject.Direction.DOWN;
        if (node.children[0] != null)
        {

            foreach (XMLNode property in ((XMLNode)node.children[0]).children)
            {
                switch (property.attributes["name"].ToLower())
                {
                    case "interval":
                        float.TryParse(property.attributes["value"], out interval);
                        break;
                    case "direction":
                        switch (property.attributes["value"].ToUpper())
                        {
                            case "UP": turretDirection = FutileFourDirectionBaseObject.Direction.UP; break;
                            case "RIGHT": turretDirection = FutileFourDirectionBaseObject.Direction.RIGHT; break;
                            case "DOWN": turretDirection = FutileFourDirectionBaseObject.Direction.DOWN; break;
                            case "LEFT": turretDirection = FutileFourDirectionBaseObject.Direction.LEFT; break;
                        }
                        break;
                    case "initdelay":
                        float.TryParse(property.attributes["value"], out initdelay);
                        break;
                }
            }
        }
        ArrowTurret result = new ArrowTurret(interval, initdelay, world);
        result.SetDirection(turretDirection);
        result.PlayAnim();
        result.SetPosition((float.Parse(node.attributes["x"]) + 8f), -(float.Parse(node.attributes["y"]) - 8f));

        return result;
    }
示例#41
0
 //---------------------------------------------------------------------------------
 // Start
 //---------------------------------------------------------------------------------
 public XMLOutStream Start(string tag)
 {
     if(current == null)
         current = new XMLNode(tag);
     else
     {
         XMLNode child = new XMLNode(tag);
         current.AddChild(child);
         current = child;
     }
     return this;
 }
示例#42
0
    public int Push(XMLNode item)
    {
        Add(item);

        return this.Count;
    }
示例#43
0
    public XMLNode read( String xml )
    {
        int index = 0;
        int lastIndex = 0;
        XMLNode rootNode = new XMLNode();
        XMLNode currentNode = rootNode;

        while ( true )
        {
            index = xml.IndexOf(TAG_START, lastIndex );

            if ( index < 0 || index >= xml.Length )
            {
				//Debug.Log("XMLReader: Exit on index " + index);
                break;
            }
			
			
			// check for untagged text between index and lastIndex
			int lengthCheck = (index - lastIndex) - 1;
			if (lengthCheck > 0) {
				String xmlText = xml.Substring( lastIndex + 1, lengthCheck ).Trim();
				if (xmlText != "" && xmlText != "<") {
					//Debug.Log("XMLReader: Text Between indexes " + xmlText);
					currentNode.value = xmlText;
				}
			}
			
            index++;

            lastIndex = xml.IndexOf(TAG_END, index);
            if ( lastIndex < 0 || lastIndex >= xml.Length )
            {
				//Debug.Log("XMLReader: Exit on lastIndex " + lastIndex);
                break;
            }

            int tagLength = lastIndex - index;
            String xmlTag = xml.Substring( index, tagLength );
			
			//Debug.Log("XMLReader: Find text: " + xmlTag);
			
            // The tag starts with "<?"
            if (xmlTag[0] == QUESTION) {
				//Debug.Log("XMLReader: Question " + xmlTag);
                continue;
            }
            

            // if the tag starts with a </ then it is an end tag
            if (xmlTag[0] == SLASH)
            {		
				//Debug.Log("XMLReader: Slash " + xmlTag);		
                currentNode = currentNode.parentNode;
                continue;
            }

            bool openTag = true;

            // if the tag ends in /> the tag can be considered closed
            if ( xmlTag[tagLength - 1] == SLASH)
            {
                // cut away the slash
                xmlTag = xmlTag.Substring( 0, tagLength - 1 ); 
                openTag = false;
            } else {
				//Debug.Log("XMLReader: No open tag " + xmlTag);
			}

            XMLNode node = parseTag( xmlTag );
            node.parentNode = currentNode;
            currentNode.children.Add( node );

            if ( openTag )
            {				
                currentNode = node;
            }

        }

        return rootNode;
    }
    protected virtual FNode createTilemap(XMLNode node)
    {
        XMLNode csvData = new XMLNode();
        XMLNode properties = new XMLNode();
        foreach (XMLNode child in node.children) {
            if (child.tagName == "data") {
                csvData = child;
            } else if (child.tagName == "properties") {
                properties = child;
            }
        }

        // make sure encoding is set to csv
        if (csvData.attributes["encoding"] != "csv") {
            Debug.Log ("FTiledScene: Could not render layer data, encoding set to: " + csvData.attributes["encoding"]);
            return null;
        }

        // remember name
        _layerNames.Add (node.attributes["name"]);

        // skipZero, if this is true all filled tiles will be drawn without clipping
        bool skipZero = false;

        // do stuff with properties
        foreach (XMLNode property in properties.children) {
            // check each property
            if (property.attributes["name"] == "skipZero") {
                skipZero = bool.Parse(property.attributes["value"]);
            }
        }

        // get text for csv data
        string csvText = csvData.value;
        string firstFrame = csvText.Substring( 0, csvText.IndexOf(',') );
        int firstID = RemoveFrameFlags(uint.Parse(firstFrame));

        // find name of tileset being used, assumes all tiles are from the same tileset
        string baseName = this.getTilesetNameForID(firstID);

        // create tilemap
        FTilemap tilemap = new FTilemap(baseName);
        if (!skipZero) {
            tilemap.clipToScreen = true;
            tilemap.clipNode = _clipNode;
        }
        tilemap.LoadText(csvText, skipZero);

        return tilemap;
    }
示例#45
0
 //---------------------------------------------------------------------------------
 // End
 //---------------------------------------------------------------------------------
 public XMLInStream End()
 {
     if(current.parent == null)
     {
         Debug.LogError("No parent node for tag: " + current.tag);
         return null;
     }
     current = current.parent;
     return this;
 }
示例#46
0
 //---------------------------------------------------------------------------------
 // Constructor
 //---------------------------------------------------------------------------------
 public XMLParser()
 {
     elements = new Stack();
     currentElement = null;
 }
示例#47
0
 private static EnemySpawn parseEnemySpawn(XMLNode node, World world)
 {
     EnemySpawn result = new EnemySpawn(new Vector2(float.Parse(node.attributes["x"]) + 8f, -(float.Parse(node.attributes["y"]) - 8f)));
     return result;
 }
示例#48
0
    //---------------------------------------------------------------------------------
    // Parse
    //---------------------------------------------------------------------------------
    public XMLNode Parse(FlashCompatibleTextReader reader)
    {
        this.reader = reader;

        //check empty string
        if(reader.Peek() == -1)
            return null;

        // skip xml declaration or DocTypes
        SkipPrologs();

        //check empty string
        if(reader.Peek() == -1)
            return null;

        while (true)
        {
            SkipWhitespace();
            int index;
            string tagName;

            // remove the prepend or trailing white spaces
            bool startingBracket = (char)reader.Peek() == '<';
            string currentTag = ReadTag(startingBracket).Trim();
            if(currentTag.StartsWith("<!"))
            {
                // Nothing to do, it's a comment
            }
            else if (currentTag.StartsWith("</"))
            {
                // close tag
                tagName = currentTag.Substring(2, currentTag.Length-3);

                // no open tag
                if (currentElement == null)
                {
                    Debug.LogError("Got close tag '" + tagName +
                            "' without open tag.");
                    return null;
                }

                // close tag does not match with open tag
                if (tagName != currentElement.tag)
                {
                    Debug.LogError("Expected close tag for '" +
                                currentElement.tag + "' but got '" +
                             tagName + "'.");
                    return null;
                }

                if (elements.Count == 0)
                    return currentElement;
                else
                    currentElement = (XMLNode)elements.Pop();

            }
            else
            {
                // open tag or tag with both open and close tags
                index = currentTag.IndexOf('"');
                if(index < 0)
                    index = currentTag.IndexOf('\'');

                if (index < 0) {
                    // tag with no attributes
                    if (currentTag.EndsWith("/>"))
                    {
                        // close tag as well
                        tagName = currentTag.Substring(1, currentTag.Length-3).Trim();
                        currentTag = "/>";
                    }
                    else
                    {
                        // open tag
                        tagName = currentTag.Substring(1, currentTag.Length-2).Trim();
                        currentTag = "";
                    }
                }
                else
                {
                    // tag with attributes
                    int endtagIndex = currentTag.IndexOf(" ");
                    tagName = currentTag.Substring(1, endtagIndex).Trim();
                    currentTag = currentTag.Substring(endtagIndex+1);
                }

                // create new element
                XMLNode element = new XMLNode(tagName);

                // parse the attributes
                bool isTagClosed = false;
                while (currentTag.Length > 0)
                {
                    // remove the prepend or trailing white spaces
                    currentTag = currentTag.Trim();

                    if (currentTag == "/>")
                    {
                        // close tag
                        isTagClosed = true;
                        break;
                    }
                    else if (currentTag == ">")
                    {
                        // open tag
                        break;
                    }

                    index = currentTag.IndexOf("=");
                    if (index < 0)
                    {
                        Debug.LogError("Invalid attribute for tag '" +
                                tagName + "'.");
                        return null;
                    }

                    // get attribute name
                    string attributeName = currentTag.Substring(0, index);
                    currentTag = currentTag.Substring(index+1);

                    // get attribute value
                    string attributeValue;
                    bool isQuoted = true;
                    if (currentTag.StartsWith("\""))
                    {
                        index = currentTag.IndexOf('"', 1);
                    }
                    else if (currentTag.StartsWith("'"))
                    {
                        index = currentTag.IndexOf('\'', 1);
                    }
                    else
                    {
                        isQuoted = false;
                        index = currentTag.IndexOf(' ');
                        if (index < 0) {
                            index = currentTag.IndexOf('>');
                            if (index < 0) {
                                index = currentTag.IndexOf('/');
                            }
                        }
                    }

                    if (index < 0)
                    {
                        Debug.LogError("Invalid attribute for tag '" +
                                tagName + "'.");
                        return null;
                    }

                    if (isQuoted)
                        attributeValue = currentTag.Substring(1, index -1);
                    else
                        attributeValue = currentTag.Substring(0, index - 1);

                    // add attribute to the new element
                    element.attributes[attributeName]= attributeValue;

                    currentTag = currentTag.Substring(index+1);
                }

                // read the text between the open and close tag
                if (!isTagClosed)
                    element.content = ReadText();

                // add new element as a child element of
                // the current element
                if (currentElement != null)
                    currentElement.AddChild(element);

                if (!isTagClosed)
                {
                    if (currentElement != null)
                        elements.Push(currentElement);

                    currentElement = element;
                }
                else if (currentElement == null)
                {
                    // only has one tag in the document
                    return element;
                }
            }
        }
    }
    public static int Main(string[] args)
    {
        if (args.Length != 2)
        {
            Console.WriteLine("  usage: addingEvidenceCodes_2 <input-filename> <output-filename>");
            Console.WriteLine("  Adds controlled vocabulary term to a species");
            Console.WriteLine();
            return 2;
        }

        SBMLDocument d = libsbml.readSBML(args[0]);
        long errors = d.getNumErrors();

        if (errors > 0)
        {
            Console.WriteLine("Read Error(s):");
            d.printErrors();

            Console.WriteLine("Correct the above and re-run.");
        }
        else
        {
            long n = d.getModel().getNumSpecies();

            if (n <= 0)
            {
                Console.WriteLine("Model has no species.\n Cannot add CV terms\n");
            }
            else
            {
                Species s = d.getModel().getSpecies(0);

                /* check that the species has a metaid
           * no CVTerms will be added if there is no metaid to reference
           */
                if (!s.isSetMetaId())
                    s.setMetaId("metaid_0000052");

                CVTerm cv1 = new CVTerm(libsbml.BIOLOGICAL_QUALIFIER);
                cv1.setBiologicalQualifierType(libsbml.BQB_OCCURS_IN);
                cv1.addResource("urn:miriam:obo.go:GO%3A0005764");

                s.addCVTerm(cv1);

                // now create the additional annotation

                //<rdf:Statement>
                //  <rdf:subject rdf:resource="#metaid_0000052"/>
                //  <rdf:predicate rdf:resource="http://biomodels.net/biology-qualifiers/occursIn"/>
                //  <rdf:object rdf:resource="urn:miriam:obo.go:GO%3A0005764"/>
                //  <bqbiol:isDescribedBy>
                //    <rdf:Bag>
                //      <rdf:li rdf:resource="urn:miriam:obo.eco:ECO%3A0000004"/>
                //      <rdf:li rdf:resource="urn:miriam:pubmed:7017716"/>
                //    </rdf:Bag>
                //  </bqbiol:isDescribedBy>
                //</rdf:Statement>

                /* attributes */
                XMLAttributes blank_att = new XMLAttributes();

                XMLAttributes resource_att = new XMLAttributes();

                /* create the outer statement node */
                XMLTriple statement_triple = new XMLTriple("Statement",
                                                       "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                       "rdf");

                XMLToken statement_token = new XMLToken(statement_triple, blank_att);

                XMLNode statement = new XMLNode(statement_token);

                /*create the subject node */
                XMLTriple subject_triple = new XMLTriple("subject",
                                                     "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                     "rdf");

                resource_att.clear();
                resource_att.add("rdf:resource", "#" + s.getMetaId());

                XMLToken subject_token = new XMLToken(subject_triple, resource_att);

                XMLNode subject = new XMLNode(subject_token);

                /*create the predicate node */
                XMLTriple predicate_triple = new XMLTriple("predicate",
                                                       "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                       "rdf");

                resource_att.clear();
                resource_att.add("rdf:resource",
                                 "http://biomodels.net/biology-qualifiers/occursIn");

                XMLToken predicate_token = new XMLToken(predicate_triple, resource_att);

                XMLNode predicate = new XMLNode(predicate_token);

                /*create the object node */
                XMLTriple object_triple = new XMLTriple("object",
                                                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                    "rdf");

                resource_att.clear();
                resource_att.add("rdf:resource", "urn:miriam:obo.go:GO%3A0005764");

                XMLToken object_token = new XMLToken(object_triple, resource_att);

                XMLNode object_ = new XMLNode(object_token);

                /* create the bqbiol node */
                XMLTriple bqbiol_triple = new XMLTriple("isDescribedBy",
                                                    "http://biomodels.net/biology-qualifiers/",
                                                    "bqbiol");

                XMLToken bqbiol_token = new XMLToken(bqbiol_triple, blank_att);

                XMLNode bqbiol = new XMLNode(bqbiol_token);

                /* create the bag node */
                XMLTriple bag_triple = new XMLTriple("Bag",
                                                 "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                 "rdf");

                XMLToken bag_token = new XMLToken(bag_triple, blank_att);

                XMLNode bag = new XMLNode(bag_token);

                /* create each li node and add to the bag */
                XMLTriple li_triple = new XMLTriple("li",
                                                "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                "rdf");

                resource_att.clear();
                resource_att.add("rdf:resource", "urn:miriam:obo.eco:ECO%3A0000004");

                XMLToken li_token = new XMLToken(li_triple, resource_att);
                li_token.setEnd();

                XMLNode li = new XMLNode(li_token);

                bag.addChild(li);

                resource_att.clear();
                resource_att.add("rdf:resource", "urn:miriam:pubmed:7017716");
                li_token = new XMLToken(li_triple, resource_att);
                li_token.setEnd();
                li = new XMLNode(li_token);

                bag.addChild(li);

                /* add the bag to bqbiol */
                bqbiol.addChild(bag);

                /* add subject, predicate, object and bqbiol to statement */
                statement.addChild(subject);
                statement.addChild(predicate);
                statement.addChild(object_);
                statement.addChild(bqbiol);

                /* create a top-level RDF element
           * this will ensure correct merging
           */

                XMLNamespaces xmlns = new XMLNamespaces();
                xmlns.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
                xmlns.add("http://purl.org/dc/elements/1.1/", "dc");
                xmlns.add("http://purl.org/dc/terms/", "dcterms");
                xmlns.add("http://www.w3.org/2001/vcard-rdf/3.0#", "vCard");
                xmlns.add("http://biomodels.net/biology-qualifiers/", "bqbiol");
                xmlns.add("http://biomodels.net/model-qualifiers/", "bqmodel");

                XMLTriple RDF_triple = new XMLTriple("RDF",
                                                 "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                                 "rdf");

                XMLToken RDF_token = new XMLToken(RDF_triple, blank_att, xmlns);

                XMLNode annotation = new XMLNode(RDF_token);

                /* add the staement node to the RDF node */
                annotation.addChild(statement);

                s.appendAnnotation(annotation);

                libsbml.writeSBML(d, args[1]);
            }
        }

        return (int)errors;
    }
示例#50
0
文件: XMLReader.cs 项目: Morac/Orca6
    public XMLNode read(String xml)
    {
        int index = 0;
        int lastIndex = 0;
        XMLNode rootNode = new XMLNode();
        XMLNode currentNode = rootNode;

        while ( true )
        {
            index = xml.IndexOf(TAG_START, lastIndex);

            if ( index < 0 || index >= xml.Length )
            {
                break;
            }

            index++;

            lastIndex = xml.IndexOf(TAG_END, index);
            if ( lastIndex < 0 || lastIndex >= xml.Length )
            {
                break;
            }

            int tagLength = lastIndex - index;
            String xmlTag = xml.Substring(index, tagLength);

            // if the tag starts with a </ then it is an end tag
            //
            if ( xmlTag[0] == SLASH )
            {
                currentNode = currentNode.parentNode;
                continue;
            }

            bool openTag = true;

            // if the tag ends in /> the tag can be considered closed
            if ( xmlTag[tagLength - 1] == SLASH )
            {
                // cut away the slash
                xmlTag = xmlTag.Substring(0, tagLength - 1);
                openTag = false;
            }

            XMLNode node = parseTag(xmlTag);
            node.parentNode = currentNode;
            currentNode.children.Add(node);

            if ( openTag )
            {
                currentNode = node;
            }

        }

        return rootNode;
    }
    protected virtual FNode createObject(XMLNode node)
    {
        // type
        string type = node.attributes["type"];

        // get x,y
        int givenX = int.Parse(node.attributes["x"]);
        int givenY = int.Parse(node.attributes["y"]);

        // remove extension from type
        int startIndex = type.LastIndexOf('/') + 1;
        int endIndex = type.LastIndexOf('.');
        int length = endIndex - startIndex;
        if (length < 0) {
            length = type.Length - startIndex;
        }
        string spriteElement = type.Substring( startIndex , length);

        FSprite sprite = new FSprite(spriteElement);
        sprite.x = givenX + sprite.width / 2;
        sprite.y = -givenY + sprite.height / 2;

        return sprite;
    }
    protected virtual FNode createTileObject(XMLNode node)
    {
        // get id numbers needed
        int id = int.Parse(node.attributes["gid"]);
        int firstID = this.getTilesetFirstIDForID(id);

        // find parts of source image
        string baseName = this.getTilesetNameForID(id);
        int actualFrame = id - firstID + objectStartInt;

        // assemble whole name
        string name = baseName + "_" + actualFrame;

        // get x,y
        int givenX = int.Parse(node.attributes["x"]);
        int givenY = int.Parse(node.attributes["y"]);

        FSprite sprite = new FSprite(name);
        sprite.x = givenX + sprite.width / 2;
        sprite.y = -givenY + sprite.height / 2;

        return sprite;
    }
示例#53
0
 //---------------------------------------------------------------------------------
 // Constructor
 //---------------------------------------------------------------------------------
 public XMLInStream(XMLNode node)
 {
     current = node;
 }
示例#54
0
        public object Parse(string content)
        {

            XMLNode rootNode = new XMLNode();
            rootNode["_text"] = "";

            //string nodeContents = "";

            bool inElement = false;
            bool collectNodeName = false;
            bool collectAttributeName = false;
            bool collectAttributeValue = false;
            bool quoted = false;
            string attName = "";
            string attValue = "";
            string nodeName = "";
            string textValue = "";

            bool inMetaTag = false;
            bool inComment = false;
            bool inCDATA = false;

            XMLNodeList parents = new XMLNodeList();

            XMLNode currentNode = rootNode;
            for (int i = 0; i < content.Length; i++)
            {

                char c = content[i];
                char cn = 'x';
                char cnn = 'x';
                char cp = 'x';
                if ((i + 1) < content.Length) cn = content[i + 1];
                if ((i + 2) < content.Length) cnn = content[i + 2];
                if (i > 0) cp = content[i - 1];

                if (inMetaTag)
                {
                    if (c == QMARK && cn == GT)
                    {
                        inMetaTag = false;
                        i++;
                    }
                    continue;
                }
                else
                {
                    if (!quoted && c == LT && cn == QMARK)
                    {
                        inMetaTag = true;
                        continue;
                    }
                }

                if (inComment)
                {
                    if (cp == DASH && c == DASH && cn == GT)
                    {
                        inComment = false;
                        i++;
                    }
                    continue;
                }
                else
                {
                    if (!quoted && c == LT && cn == EXCLAMATION)
                    {

                        if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                        {
                            inCDATA = true;
                            i += 8;
                        }
                        else
                        {
                            inComment = true;
                        }
                        continue;
                    }
                }

                if (inCDATA)
                {
                    if (c == SQR && cn == SQR && cnn == GT)
                    {
                        inCDATA = false;
                        i += 2;
                        continue;
                    }
                    textValue += c;
                    continue;
                }


                if (inElement)
                {
                    if (collectNodeName)
                    {
                        if (c == SPACE)
                        {
                            collectNodeName = false;
                        }
                        else if (c == GT)
                        {
                            collectNodeName = false;
                            inElement = false;
                        }



                        if (!collectNodeName && nodeName.Length > 0)
                        {
                            if (nodeName[0] == SLASH)
                            {
                                // close tag
                                if (textValue.Length > 0)
                                {
                                    currentNode["_text"] += textValue;
                                }

                                textValue = "";
                                nodeName = "";
                                currentNode = (XMLNode)parents[(int)(parents.Count - 1)];
                                parents.RemoveAt((parents.Count-1));
                            }
                            else
                            {

                                if (textValue.Length > 0)
                                {
                                    currentNode["_text"] += textValue;
                                }
                                textValue = "";
                                XMLNode newNode = new XMLNode();
                                newNode["_text"] = "";
                                newNode["_name"] = nodeName;

                                if (currentNode[nodeName]==null)
                                {
                                    currentNode[nodeName] = new XMLNodeList();
                                }
                                ArrayList a = (ArrayList)currentNode[nodeName];
                                a.Add(newNode);
                                parents.Add(currentNode);
                                currentNode = newNode;
                                nodeName = "";
                            }
                        }
                        else
                        {
                            nodeName += c;
                        }
                    }
                    else
                    {

                        if (!quoted && c == SLASH && cn == GT)
                        {
                            inElement = false;
                            collectAttributeName = false;
                            collectAttributeValue = false;
                            if (attName!=null)
                            {
                                if (attValue!=null)
                                {
                                    currentNode["@" + attName] = attValue;
                                }
                                else
                                {
                                    currentNode["@" + attName] = true;
                                }
                            }

                            i++;
                            currentNode = (XMLNode)parents[(int)(parents.Count - 1)];
                            parents.RemoveAt((parents.Count - 1));
                            attName = "";
                            attValue = "";
                        }
                        else if (!quoted && c == GT)
                        {
                            inElement = false;
                            collectAttributeName = false;
                            collectAttributeValue = false;
                            if (attName!=null)
                            {
                                currentNode["@" + attName] = attValue;
                            }

                            attName = "";
                            attValue = "";
                        }
                        else
                        {
                            if (collectAttributeName)
                            {
                                if (c == SPACE || c == EQUALS)
                                {
                                    collectAttributeName = false;
                                    collectAttributeValue = true;
                                }
                                else
                                {
                                    attName += c;
                                }
                            }
                            else if (collectAttributeValue)
                            {
                                if (c == QUOTE)
                                {
                                    if (quoted)
                                    {
                                        collectAttributeValue = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName = "";
                                        quoted = false;
                                    }
                                    else
                                    {
                                        quoted = true;
                                    }
                                }
                                else
                                {
                                    if (quoted)
                                    {
                                        attValue += c;
                                    }
                                    else
                                    {
                                        if (c == SPACE)
                                        {
                                            collectAttributeValue = false;
                                            currentNode["@" + attName] = attValue;
                                            attValue = "";
                                            attName = "";
                                        }
                                    }
                                }
                            }
                            else if (c == SPACE)
                            {

                            }
                            else
                            {
                                collectAttributeName = true;
                                attName = "" + c;
                                attValue = "";
                                quoted = false;
                            }
                        }
                    }
                }
                else
                {
                    if (c == LT)
                    {
                        inElement = true;
                        collectNodeName = true;
                    }
                    else
                    {
                        textValue += c;
                    }

                }

            }

            return rootNode;
        }
示例#55
0
 public XMLInStream(string input)
 {
     XMLParser parser = new XMLParser();
     current = parser.Parse(new FlashCompatibleTextReader(input));
 }
示例#56
0
    public XMLNode parseTag( String xmlTag )
    {
        XMLNode node = new XMLNode();

        int nameEnd = xmlTag.IndexOf(SPACE, 0);
        if ( nameEnd < 0 )
        {
            node.tagName = xmlTag;

            return node;
        }

        String tagName = xmlTag.Substring( 0, nameEnd );
        node.tagName = tagName;

        String attrString = xmlTag.Substring( nameEnd, xmlTag.Length - nameEnd );

        return parseAttributes( attrString, node );
    }
示例#57
0
 //---------------------------------------------------------------------------------
 // Start
 //---------------------------------------------------------------------------------
 public XMLInStream Start(string tag)
 {
     foreach(XMLNode child in current.children)
         if(child.tag == tag)
         {
             current = child;
             return this;
         }
     Debug.LogError("No child node named: " + tag + " in node " + current.tag);
     return null;
 }
示例#58
0
    public void printXML( XMLNode node, int indent )
    {
        indent ++;

        foreach ( XMLNode n in node.children )
        {
            String attr = " ";
            foreach( KeyValuePair<String, String> p in n.attributes )
            {
                attr += "[" + p.Key + ": " + p.Value + "] ";
                //Debug.Log( attr );
            }

            String indentString = "";
            for ( int i=0; i< indent; i++ )
            {
                indentString += "-";
            }

            Debug.Log( "" + indentString + " " + n.tagName + attr );
            printXML(n, indent );
        }
    }   
    /**
     *
     * Creates an SBML model represented in "7.2 Example involving units"
     * in the SBML Level 2 Version 4 Specification.
     *
     */
    private static SBMLDocument createExampleInvolvingUnits()
    {
        int level = Level;
        int version = Version;

        //---------------------------------------------------------------------------
        //
        // Creates an SBMLDocument object
        //
        //---------------------------------------------------------------------------

        SBMLDocument sbmlDoc = new SBMLDocument(level, version);

        // Adds the namespace for XHTML to the SBMLDocument object.  We need this
        // because we will add notes to the model.  (By default, the SBML document
        // created by SBMLDocument only declares the SBML XML namespace.)

        sbmlDoc.getNamespaces().add("http://www.w3.org/1999/xhtml", "xhtml");

        //---------------------------------------------------------------------------
        //
        // Creates a Model object inside the SBMLDocument object.
        //
        //---------------------------------------------------------------------------

        Model model = sbmlDoc.createModel();
        model.setId("unitsExample");

        //---------------------------------------------------------------------------
        //
        // Creates UnitDefinition objects inside the Model object.
        //
        //---------------------------------------------------------------------------

        // Temporary pointers (reused more than once below).

        UnitDefinition unitdef;
        Unit unit;

        //---------------------------------------------------------------------------
        // (UnitDefinition1) Creates an UnitDefinition object ("substance").
        //
        // This has the effect of redefining the default unit of subtance for the
        // whole model.
        //---------------------------------------------------------------------------

        unitdef = model.createUnitDefinition();
        unitdef.setId("substance");

        //  Creates an Unit inside the UnitDefinition object

        unit = unitdef.createUnit();
        unit.setKind(libsbml.UNIT_KIND_MOLE);
        unit.setScale(-3);

        //--------------------------------------------------------------------------------
        // (UnitDefinition2) Creates an UnitDefinition object ("mmls")
        //--------------------------------------------------------------------------------

        // Note that we can reuse the pointers 'unitdef' and 'unit' because the
        // actual UnitDefinition object (along with the Unit objects within it)
        // is already attached to the Model object.

        unitdef = model.createUnitDefinition();
        unitdef.setId("mmls");

        //  Creates an Unit inside the UnitDefinition object ("mmls")

        unit = unitdef.createUnit();
        unit.setKind(libsbml.UNIT_KIND_MOLE);
        unit.setScale(-3);

        //  Creates an Unit inside the UnitDefinition object ("mmls")

        unit = unitdef.createUnit();
        unit.setKind(libsbml.UNIT_KIND_LITRE);
        unit.setExponent(-1);

        //  Creates an Unit inside the UnitDefinition object ("mmls")

        unit = unitdef.createUnit();
        unit.setKind(libsbml.UNIT_KIND_SECOND);
        unit.setExponent(-1);

        //--------------------------------------------------------------------------------
        // (UnitDefinition3) Creates an UnitDefinition object ("mml")
        //--------------------------------------------------------------------------------

        unitdef = model.createUnitDefinition();
        unitdef.setId("mml");

        //  Creates an Unit inside the UnitDefinition object ("mml")

        unit = unitdef.createUnit();
        unit.setKind(libsbml.UNIT_KIND_MOLE);
        unit.setScale(-3);

        //  Creates an Unit inside the UnitDefinition object ("mml")

        unit = unitdef.createUnit();
        unit.setKind(libsbml.UNIT_KIND_LITRE);
        unit.setExponent(-1);

        //---------------------------------------------------------------------------
        //
        // Creates a Compartment object inside the Model object.
        //
        //---------------------------------------------------------------------------

        Compartment comp;
        string compName = "cell";

        // Creates a Compartment object ("cell")

        comp = model.createCompartment();
        comp.setId(compName);

        // Sets the "size" attribute of the Compartment object.
        //
        //   The units of this Compartment object is the default SBML
        //   units of volume (litre), and thus we don't have to explicitly invoke
        //   setUnits("litre") function to set the default units.
        //
        comp.setSize(1);

        //---------------------------------------------------------------------------
        //
        // Creates Species objects inside the Model object.
        //
        //---------------------------------------------------------------------------

        // Temporary pointer (reused more than once below).

        Species sp;

        //---------------------------------------------------------------------------
        // (Species1) Creates a Species object ("x0")
        //---------------------------------------------------------------------------

        sp = model.createSpecies();
        sp.setId("x0");

        // Sets the "compartment" attribute of the Species object to identify the
        // compartnet in which the Species object located.

        sp.setCompartment(compName);

        // Sets the "initialConcentration" attribute of the Species object.
        //
        //  The units of this Species object is determined by two attributes of this
        //  Species object ("substanceUnits" and "hasOnlySubstanceUnits") and the
        //  "spatialDimensions" attribute of the Compartment object ("cytosol") in which
        //  this species object is located.
        //  Since the default values are used for "substanceUnits" (substance (mole))
        //  and "hasOnlySubstanceUnits" (false) and the value of "spatialDimension" (3)
        //  is greater than 0, the units of this Species object is  moles/liters .
        //
        sp.setInitialConcentration(1);

        //---------------------------------------------------------------------------
        // (Species2) Creates a Species object ("x1")
        //---------------------------------------------------------------------------

        sp = model.createSpecies();
        sp.setId("x1");
        sp.setCompartment(compName);
        sp.setInitialConcentration(1);

        //---------------------------------------------------------------------------
        // (Species3) Creates a Species object ("s1")
        //---------------------------------------------------------------------------

        sp = model.createSpecies();
        sp.setCompartment(compName);
        sp.setId("s1");
        sp.setInitialConcentration(1);

        //---------------------------------------------------------------------------
        // (Species4) Creates a Species object ("s2")
        //---------------------------------------------------------------------------

        sp = model.createSpecies();
        sp.setCompartment(compName);
        sp.setId("s2");
        sp.setInitialConcentration(1);

        //---------------------------------------------------------------------------
        //
        // Creates global Parameter objects inside the Model object.
        //
        //---------------------------------------------------------------------------

        Parameter para;

        // Creates a Parameter ("vm")

        para = model.createParameter();
        para.setId("vm");
        para.setValue(2);
        para.setUnits("mmls");

        // Creates a Parameter ("km")

        para = model.createParameter();
        para.setId("km");
        para.setValue(2);
        para.setUnits("mml");

        //---------------------------------------------------------------------------
        //
        // Creates Reaction objects inside the Model object.
        //
        //---------------------------------------------------------------------------

        // Temporary pointers.

        Reaction reaction;
        SpeciesReference spr;
        KineticLaw kl;

        //---------------------------------------------------------------------------
        // (Reaction1) Creates a Reaction object ("v1").
        //---------------------------------------------------------------------------

        reaction = model.createReaction();
        reaction.setId("v1");

        //---------------------------------------------------------------------------
        // Creates Reactant objects inside the Reaction object ("v1").
        //---------------------------------------------------------------------------

        // (Reactant1) Creates a Reactant object that references Species "x0"
        // in the model.

        spr = reaction.createReactant();
        spr.setSpecies("x0");

        //---------------------------------------------------------------------------
        // Creates a Product object inside the Reaction object ("v1").
        //---------------------------------------------------------------------------

        // Creates a Product object that references Species "s1" in the model.

        spr = reaction.createProduct();
        spr.setSpecies("s1");

        //---------------------------------------------------------------------------
        // Creates a KineticLaw object inside the Reaction object ("v1").
        //---------------------------------------------------------------------------

        kl = reaction.createKineticLaw();

        // Creates a <notes> element in the KineticLaw object.
        // Here we illustrate how to do it using a literal string.  This requires
        // known the required syntax of XHTML and the requirements for SBML <notes>
        // elements.  Later below, we show how to create notes using objects instead
        // of strings.

        string notesString = "<xhtml:p> ((vm * s1)/(km + s1)) * cell </xhtml:p>";
        kl.setNotes(notesString);

        //---------------------------------------------------------------------------
        // Creates an ASTNode object which represents the following KineticLaw object.
        //
        //  <math xmlns=\"http://www.w3.org/1998/Math/MathML\">
        //   <apply>
        //     <times/>
        //     <apply>
        //       <divide/>
        //       <apply>
        //         <times/>
        //           <ci> vm </ci>
        //           <ci> s1 </ci>
        //       </apply>
        //       <apply>
        //         <plus/>
        //           <ci> km </ci>
        //           <ci> s1 </ci>
        //       </apply>
        //     </apply>
        //     <ci> cell </ci>
        //    </apply>
        //  </math>
        //---------------------------------------------------------------------------

        //
        // In the following code, ASTNode objects, which construct an ASTNode tree
        // of the above math, are created and added in the order of preorder traversal
        // of the tree (i.e. the order corresponds to the nested structure of the above
        // MathML elements), and thus the following code maybe a bit more efficient but
        // maybe a bit difficult to read.
        //

        ASTNode astMath = new ASTNode(libsbml.AST_TIMES);

        astMath.addChild(new ASTNode(libsbml.AST_DIVIDE));
        ASTNode astDivide = astMath.getLeftChild();

        astDivide.addChild(new ASTNode(libsbml.AST_TIMES));
        ASTNode astTimes = astDivide.getLeftChild();

        astTimes.addChild(new ASTNode(libsbml.AST_NAME));
        astTimes.getLeftChild().setName("vm");

        astTimes.addChild(new ASTNode(libsbml.AST_NAME));
        astTimes.getRightChild().setName("s1");

        astDivide.addChild(new ASTNode(libsbml.AST_PLUS));
        ASTNode astPlus = astDivide.getRightChild();

        astPlus.addChild(new ASTNode(libsbml.AST_NAME));
        astPlus.getLeftChild().setName("km");

        astPlus.addChild(new ASTNode(libsbml.AST_NAME));
        astPlus.getRightChild().setName("s1");

        astMath.addChild(new ASTNode(libsbml.AST_NAME));
        astMath.getRightChild().setName("cell");

        //---------------------------------------------
        //
        // set the Math element
        //
        //------------------------------------------------

        kl.setMath(astMath);

        //---------------------------------------------------------------------------
        // (Reaction2) Creates a Reaction object ("v2").
        //---------------------------------------------------------------------------

        reaction = model.createReaction();
        reaction.setId("v2");

        //---------------------------------------------------------------------------
        // Creates Reactant objects inside the Reaction object ("v2").
        //---------------------------------------------------------------------------

        // (Reactant2) Creates a Reactant object that references Species "s1"
        // in the model.

        spr = reaction.createReactant();
        spr.setSpecies("s1");

        //---------------------------------------------------------------------------
        // Creates a Product object inside the Reaction object ("v2").
        //---------------------------------------------------------------------------

        // Creates a Product object that references Species "s2" in the model.

        spr = reaction.createProduct();
        spr.setSpecies("s2");

        //---------------------------------------------------------------------------
        // Creates a KineticLaw object inside the Reaction object ("v2").
        //---------------------------------------------------------------------------

        kl = reaction.createKineticLaw();

        // Sets a notes (by XMLNode) to the KineticLaw object.
        //
        // The following code is an alternative to using setNotes(const string&).
        // The equivalent code would be like this:
        //
        //     notesString = "<xhtml:p>((vm * s2)/(km + s2))*cell</xhtml:p>";
        //     kl.setNotes(notesString);

        // Creates an XMLNode of start element (<xhtml:p>) without attributes.

        XMLNode notesXMLNode = new XMLNode(
            new XMLTriple("p", "", "xhtml"),
            new XMLAttributes());

        // Adds a text element to the start element.

        notesXMLNode.addChild(new XMLNode(" ((vm * s2)/(km + s2)) * cell "));

        // Adds it to the kineticLaw object.

        kl.setNotes(notesXMLNode);

        //---------------------------------------------------------------------------
        // Sets a math (ASTNode object) to the KineticLaw object.
        //---------------------------------------------------------------------------

        // To create mathematical expressions, one would typically construct
        // an ASTNode tree as the above example code which creates a math of another
        // KineticLaw object.  Here, to save some space and illustrate another approach
        // of doing it, we will write out the formula in MathML form and then use a
        // libSBML convenience function to create the ASTNode tree for us.
        // (This is a bit dangerous; it's very easy to make mistakes when writing MathML
        // by hand, so in a real program, we would not really want to do it this way.)

        string mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
        + "  <apply>"
        + "    <times/>"
        + "    <apply>"
        + "      <divide/>"
        + "      <apply>"
        + "        <times/>"
        + "        <ci> vm </ci>"
        + "        <ci> s2 </ci>"
        + "      </apply>"
        + "      <apply>"
        + "        <plus/>"
        + "          <ci> km </ci>"
        + "          <ci> s2 </ci>"
        + "      </apply>"
        + "    </apply>"
        + "    <ci> cell </ci>"
        + "  </apply>"
        + "</math>";

        astMath = libsbml.readMathMLFromString(mathXMLString);
        kl.setMath(astMath);

        //---------------------------------------------------------------------------
        // (Reaction3) Creates a Reaction object ("v3").
        //---------------------------------------------------------------------------

        reaction = model.createReaction();
        reaction.setId("v3");

        //---------------------------------------------------------------------------
        // Creates Reactant objects inside the Reaction object ("v3").
        //---------------------------------------------------------------------------

        // (Reactant2) Creates a Reactant object that references Species "s2"
        // in the model.

        spr = reaction.createReactant();
        spr.setSpecies("s2");

        //---------------------------------------------------------------------------
        // Creates a Product object inside the Reaction object ("v3").
        //---------------------------------------------------------------------------

        // Creates a Product object that references Species "x1" in the model.

        spr = reaction.createProduct();
        spr.setSpecies("x1");

        //---------------------------------------------------------------------------
        // Creates a KineticLaw object inside the Reaction object ("v3").
        //---------------------------------------------------------------------------

        kl = reaction.createKineticLaw();

        // Sets a notes (by string) to the KineticLaw object.

        notesString = "<xhtml:p> ((vm * x1)/(km + x1)) * cell </xhtml:p>";
        kl.setNotes(notesString);

        //---------------------------------------------------------------------------
        // Sets a math (ASTNode object) to the KineticLaw object.
        //---------------------------------------------------------------------------

        mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
        + "  <apply>"
        + "    <times/>"
        + "    <apply>"
        + "      <divide/>"
        + "      <apply>"
        + "        <times/>"
        + "        <ci> vm </ci>"
        + "        <ci> x1 </ci>"
        + "      </apply>"
        + "      <apply>"
        + "        <plus/>"
        + "          <ci> km </ci>"
        + "          <ci> x1 </ci>"
        + "      </apply>"
        + "    </apply>"
        + "    <ci> cell </ci>"
        + "  </apply>"
        + "</math>";

        astMath = libsbml.readMathMLFromString(mathXMLString);
        kl.setMath(astMath);

        // Returns the created SBMLDocument object.
        // The returned object must be explicitly deleted by the caller,
        // otherwise memory leak will happen.

        return sbmlDoc;
    }
    protected virtual FNode createObjectLayer(XMLNode node)
    {
        // add objects to FContainers
        FContainer objectGroup = new FContainer();

        foreach (XMLNode fObject in node.children) {
            if (fObject.tagName == "object") {
                if (fObject.attributes.ContainsKey("gid")) {
                    // create FSprite (override that function for specific class changes)
                    objectGroup.AddChild(this.createTileObject(fObject));
                } else {
                    FNode newObject = this.createObject(fObject);
                    if (newObject != null) {
                        objectGroup.AddChild(newObject);
                    }
                }
            }
        }

        // remember name
        _layerNames.Add (node.attributes["name"]);

        // add to self
        return objectGroup;
    }