GetNextXMLFieldName() public static method

public static GetNextXMLFieldName ( string input ) : string
input string
return string
Beispiel #1
0
        // Creates a VREvent from an XML-formatted description.  xmlDescription is modified as part of the constructor.
        // Following the current C++ implementation of MinVR, events are serialized in an XML defined by the C++
        // VRDataIndex class.  This constructor pops the first <MyEventName>...</MyEventName> field off of xmlDescription
        // to create the event and xmlDescription is set to whatever remains in the string.
        public VREvent(ref string xmlDescription)
        {
            // TODO 1: It might be faster to use C#'s XMLReader object to parse the XML.  The XMLUtils class
            // was never intended to be used during the rendering loop, just for config files.

            // TODO 2: It might be even faster to convert the entire serialization scheme to use binary!

            _name = XMLUtils.GetNextXMLFieldName(xmlDescription);

            Dictionary <string, string> props = new Dictionary <string, string>();
            string xmlData      = string.Empty;
            string xmlRemaining = string.Empty;
            bool   success      = XMLUtils.GetXMLField(xmlDescription, _name, ref props, ref xmlData, ref xmlRemaining);

            if (!success)
            {
                Debug.Log("Error decoding VRDataIndex");
                return;
            }

            string nextField = XMLUtils.GetNextXMLFieldName(xmlData);

            while (nextField != string.Empty)
            {
                string datumValue       = string.Empty;
                string xmlDataRemaining = string.Empty;
                success = XMLUtils.GetXMLField(xmlData, nextField, ref props, ref datumValue, ref xmlDataRemaining);
                if (!success)
                {
                    Debug.Log("Error decoding VRDatum named " + nextField);
                    return;
                }

                char[] separatingChars = { ',' };
                if (props["type"] == "int")
                {
                    //Debug.Log ("Got int: " + nextField + "=" + datumValue);
                    AddData(nextField, Convert.ToInt32(datumValue));
                }
                else if (props["type"] == "float")
                {
                    //Debug.Log ("Got float: " + nextField + "=" + datumValue);
                    AddData(nextField, Convert.ToSingle(datumValue));
                }
                else if (props["type"] == "string")
                {
                    //Debug.Log ("Got string: " + nextField + "=" + datumValue);
                    AddData(nextField, datumValue);
                }
                else if (props["type"] == "intarray")
                {
                    //Debug.Log ("Got intarray: " + nextField + "=" + datumValue);
                    string[] elements = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    int[]    intarray = new int[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        intarray[i] = Convert.ToInt32(elements[i]);
                    }
                    AddData(nextField, intarray);
                }
                else if (props["type"] == "floatarray")
                {
                    //Debug.Log ("Got floatarray: " + nextField + "=" + datumValue);
                    string[] elements   = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    float[]  floatarray = new float[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        floatarray[i] = Convert.ToSingle(elements[i]);
                    }
                    AddData(nextField, floatarray);
                }
                else if (props["type"] == "stringarray")
                {
                    //Debug.Log ("Got stringarray: " + nextField + "=" + datumValue);
                    string[] elements = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    string[] strarray = new string[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        strarray[i] = elements[i];
                    }
                    AddData(nextField, strarray);
                }
                else
                {
                    Debug.Log("Unknown VRDatum type: " + props["type"]);
                }

                xmlData   = xmlDataRemaining;
                nextField = XMLUtils.GetNextXMLFieldName(xmlData);
            }

            xmlDescription = xmlRemaining;
        }
Beispiel #2
0
        // Creates a VRDataIndex from an XML-formatted description.  xmlDescription is modified as part of the constructor.  The
        // first VRDataIndex described <VRDataIndex>...</VRDataIndex> is popped off the string and xmlDescription is set to whatever
        // remains in the string.
        public VRDataIndex(ref string xmlDescription)
        {
            _hash = new Hashtable();

            _name = XMLUtils.GetNextXMLFieldName(xmlDescription);

            Dictionary <string, string> props = new Dictionary <string, string>();
            string xmlData      = string.Empty;
            string xmlRemaining = string.Empty;
            bool   success      = XMLUtils.GetXMLField(xmlDescription, _name, ref props, ref xmlData, ref xmlRemaining);

            if (!success)
            {
                Debug.Log("Error decoding VRDataIndex");
                return;
            }

            string nextField = XMLUtils.GetNextXMLFieldName(xmlData);

            while (nextField != string.Empty)
            {
                string datumValue       = string.Empty;
                string xmlDataRemaining = string.Empty;
                success = XMLUtils.GetXMLField(xmlData, nextField, ref props, ref datumValue, ref xmlDataRemaining);
                if (!success)
                {
                    Debug.Log("Error decoding VRDatum named " + nextField);
                    return;
                }

                char[] separatingChars = { ',' };
                if (props["type"] == "int")
                {
                    //Debug.Log ("Got int: " + nextField + "=" + datumValue);
                    _hash.Add(nextField, Convert.ToInt32(datumValue));
                }
                else if (props["type"] == "float")
                {
                    //Debug.Log ("Got float: " + nextField + "=" + datumValue);
                    _hash.Add(nextField, Convert.ToSingle(datumValue));
                }
                else if (props["type"] == "double")
                {
                    //Debug.Log ("Got double: " + nextField + "=" + datumValue);
                    _hash.Add(nextField, Convert.ToDouble(datumValue));
                }
                else if (props["type"] == "string")
                {
                    //Debug.Log ("Got string: " + nextField + "=" + datumValue);
                    _hash.Add(nextField, datumValue);
                }
                else if (props["type"] == "intarray")
                {
                    //Debug.Log ("Got intarray: " + nextField + "=" + datumValue);
                    string[] elements = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    int[]    intarray = new int[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        intarray[i] = Convert.ToInt32(elements[i]);
                    }
                    _hash.Add(nextField, intarray);
                }
                else if (props["type"] == "floatarray")
                {
                    //Debug.Log ("Got floatarray: " + nextField + "=" + datumValue);
                    string[] elements   = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    float[]  floatarray = new float[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        floatarray[i] = Convert.ToSingle(elements[i]);
                    }
                    _hash.Add(nextField, floatarray);
                }
                else if (props["type"] == "doublearray")
                {
                    //Debug.Log ("Got doublearray: " + nextField + "=" + datumValue);
                    string[] elements    = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    double[] doublearray = new double[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        doublearray[i] = Convert.ToDouble(elements[i]);
                    }
                    _hash.Add(nextField, doublearray);
                }
                else if (props["type"] == "stringarray")
                {
                    //Debug.Log ("Got stringarray: " + nextField + "=" + datumValue);
                    string[] elements = datumValue.Split(separatingChars, System.StringSplitOptions.RemoveEmptyEntries);
                    string[] strarray = new string[elements.Length];
                    for (int i = 0; i < elements.Length; i++)
                    {
                        strarray[i] = elements[i];
                    }
                    _hash.Add(nextField, strarray);
                }
                else
                {
                    Debug.Log("Unknown VRDatum type: " + props["type"]);
                }

                xmlData   = xmlDataRemaining;
                nextField = XMLUtils.GetNextXMLFieldName(xmlData);
            }

            xmlDescription = xmlRemaining;
        }