Example #1
0
        private void ReadXmlDocument(XmlDocument xmlDoc)
        {
            XmlNode rootXmlNode = xmlDoc.DocumentElement;

            //make sure it is actually an xml node
            if (rootXmlNode.NodeType == XmlNodeType.Element)
            {
                //eat up the name of that xml node
                string strElementName = rootXmlNode.Name;
                if ("bulletml" != strElementName)
                {
                    //The first node HAS to be bulletml
                    throw new Exception("Error reading \"" + Filename + "\": XML root node needs to be \"bulletml\", found \"" + strElementName + "\" instead");
                }

                //Create the root node of the bulletml tree
                RootNode = new BulletMLNode(ENodeName.bulletml);

                //Read in the whole bulletml tree
                RootNode.Parse(rootXmlNode, null);

                //Find what kind of pattern this is: horizontal or vertical
                XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                for (int i = 0; i < mapAttributes.Count; i++)
                {
                    //will only have the name attribute
                    string strName  = mapAttributes.Item(i).Name;
                    string strValue = mapAttributes.Item(i).Value;
                    if ("type" == strName)
                    {
                        //if  this is a top level node, "type" will be veritcal or horizontal
                        Orientation = StringToPatternType(strValue);
                    }
                }
            }
        }
Example #2
0
        protected static void ParseExternalAttributes(XmlElement element, Field field)
        {
            XmlNamedNodeMap attributes = element.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                var attribute = (XmlAttribute)attributes.Item(i);
                if (string.IsNullOrEmpty(attribute.NamespaceURI) ||
                    attribute.NamespaceURI.Equals(FastConstants.TemplateDefinition11))
                {
                    continue;
                }
                field.AddAttribute(new QName(attribute.LocalName, attribute.NamespaceURI), attribute.Value);
            }
        }
Example #3
0
        public void TestMethod1()
        {
            string folderPath = @"./data/xml/classes";

            foreach (string file in Directory.EnumerateFiles(folderPath, "*.xml"))
            {
                string contents = File.ReadAllText(file);
            }

            XmlDocument doc = new XmlDocument();

            string[] xmlFilesArray = Directory.GetFiles(@"data\xml\classes\");
            for (int i = 0; i < xmlFilesArray.Length; i++)
            {
                doc.Load(xmlFilesArray[i]);
                XmlNodeList nodes = doc.DocumentElement.SelectNodes("/list/class");

                foreach (XmlNode node in nodes)
                {
                    if ("class".Equals(node.Attributes[0].OwnerElement.Name))
                    {
                        XmlNamedNodeMap attrs   = node.Attributes;
                        ClassIds        classId = (ClassIds)int.Parse(attrs.Item(0).Value);
                        StatsSet        set     = new StatsSet();

                        for (XmlNode cd = node.FirstChild; cd != null; cd = cd.NextSibling)
                        {
                            if ("set".Equals(cd.NextSibling.Name) && cd.NextSibling != null)
                            {
                                attrs = cd.NextSibling.Attributes;
                                string name  = attrs.GetNamedItem("name").Value;
                                string value = attrs.GetNamedItem("val").Value;
                                set.Set(name, value);
                            }
                            else
                            {
                                break;
                            }
                        }
                        ////PcTemplate pcTempl = new PcTemplate(classId, set);
                        ////templates.Add((int)pcTempl.ClassId, pcTempl);
                        //System.Diagnostics.Trace.WriteLine("Added template for: " + pcTempl.ClassId);
                    }
                }
            }
        }
Example #4
0
        /**
         * Creates a new Preload from an xml node.
         *
         * @param preload The Preload to create
         * @throws SpecParserException When the href is not specified
         */
        public Preload(XmlElement preload, Uri _base)
        {
            this._base = _base;
            href       = XmlUtil.getUriAttribute(preload, "href");
            if (href == null)
            {
                throw new SpecParserException("Preload/@href is missing or invalid.");
            }

            // Record all the associated views
            String           viewNames = XmlUtil.getAttribute(preload, "views", "");
            HashSet <String> views     = new HashSet <String>();

            foreach (String _s in viewNames.Split(','))
            {
                String s = _s.Trim();
                if (s.Length > 0)
                {
                    views.Add(s.Trim());
                }
            }
            this.views = views;

            auth       = AuthType.Parse(XmlUtil.getAttribute(preload, "authz"));
            signOwner  = XmlUtil.getBoolAttribute(preload, "sign_owner", true);
            signViewer = XmlUtil.getBoolAttribute(preload, "sign_viewer", true);
            Dictionary <String, String> attributes = new Dictionary <string, string>();
            XmlNamedNodeMap             attrs      = preload.Attributes;

            for (int i = 0; i < attrs.Count; ++i)
            {
                XmlNode attr = attrs.Item(i);
                if (!KNOWN_ATTRIBUTES.Contains(attr.Name))
                {
                    attributes.Add(attr.Name, attr.Value);
                }
            }
            this.attributes = attributes;
        }
Example #5
0
        /**
         * @param elements List of all views, in order, that make up this view.
         *     An ordered list is required per the spec, since values must
         *     overwrite one another.
         * @throws SpecParserException
         */
        public View(String name, List <XmlElement> elements, Uri _base)
        {
            this.name  = name;
            this._base = _base;
            bool        quirks                     = true;
            Uri         href                       = null;
            String      contentType                = null;
            ContentType type                       = null;
            int         preferredHeight            = 0;
            int         preferredWidth             = 0;
            String      auth                       = null;
            bool        signOwner                  = true;
            bool        signViewer                 = true;
            Dictionary <String, String> attributes = new Dictionary <string, string>();
            StringBuilder content                  = new StringBuilder();

            foreach (XmlElement element in elements)
            {
                contentType = XmlUtil.getAttribute(element, "type");
                if (contentType != null)
                {
                    ContentType newType = ContentType.Parse(contentType);
                    if (type != null && newType != type)
                    {
                        throw new SpecParserException("You may not mix content types in the same view.");
                    }
                    else
                    {
                        type = newType;
                    }
                }
                href            = XmlUtil.getUriAttribute(element, "href", href);
                quirks          = XmlUtil.getBoolAttribute(element, "quirks", quirks);
                preferredHeight = XmlUtil.getIntAttribute(element, "preferred_height");
                preferredWidth  = XmlUtil.getIntAttribute(element, "preferred_width");
                auth            = XmlUtil.getAttribute(element, "authz", auth);
                signOwner       = XmlUtil.getBoolAttribute(element, "sign_owner", signOwner);
                signViewer      = XmlUtil.getBoolAttribute(element, "sign_viewer", signViewer);
                content.Append(element.InnerText);
                XmlNamedNodeMap attrs = element.Attributes;
                for (int i = 0; i < attrs.Count; ++i)
                {
                    XmlNode attr = attrs.Item(i);
                    if (!KNOWN_ATTRIBUTES.Contains(attr.Name))
                    {
                        attributes.Add(attr.Name, attr.Value);
                    }
                }
            }
            this.content = content.ToString();
            this.needsUserPrefSubstitution = this.content.Contains("__UP_");
            this.quirks          = quirks;
            this.href            = href;
            this.rawType         = contentType ?? "html";
            this.type            = type ?? ContentType.HTML;
            this.preferredHeight = preferredHeight;
            this.preferredWidth  = preferredWidth;
            this.attributes      = attributes;
            this.authType        = AuthType.Parse(auth);
            this.signOwner       = signOwner;
            this.signViewer      = signViewer;
            if (type == ContentType.URL && this.href == null)
            {
                throw new SpecParserException("Content@href must be set when Content@type is \"url\".");
            }
        }
Example #6
0
        /// <summary>
        /// Parse the specified bulletNodeElement.
        /// Read all the data from the xml node into this dude.
        /// </summary>
        /// <param name="bulletNodeElement">Bullet node element.</param>
        public void Parse(XmlNode bulletNodeElement, BulletMLNode parentNode)
        {
            // Handle null argument.
            if (null == bulletNodeElement)
            {
                throw new ArgumentNullException("bulletNodeElement");
            }

            //grab the parent node
            Parent = parentNode;

            //Parse all our attributes
            XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes;

            for (int i = 0; i < mapAttributes.Count; i++)
            {
                string strName  = mapAttributes.Item(i).Name;
                string strValue = mapAttributes.Item(i).Value;

                if ("type" == strName)
                {
                    //skip the type attribute in top level nodes
                    if (ENodeName.bulletml == Name)
                    {
                        continue;
                    }

                    //get the bullet node type
                    NodeType = BulletMLNode.StringToType(strValue);
                }
                else if ("label" == strName)
                {
                    //label is just a text value
                    Label = strValue;
                }
            }

            //parse all the child nodes
            if (bulletNodeElement.HasChildNodes)
            {
                for (XmlNode childNode = bulletNodeElement.FirstChild;
                     null != childNode;
                     childNode = childNode.NextSibling)
                {
                    //if the child node is a text node, parse it into this dude
                    if (XmlNodeType.Text == childNode.NodeType)
                    {
                        //Get the text of the child xml node, but store it in THIS bullet node
                        NodeEquation.Parse(childNode.Value);
                        continue;
                    }
                    else if (XmlNodeType.Comment == childNode.NodeType)
                    {
                        //skip any comments in the bulletml script
                        continue;
                    }

                    //create a new node
                    BulletMLNode childBulletNode = NodeFactory.CreateNode(BulletMLNode.StringToName(childNode.Name));

                    //read in the node and store it
                    childBulletNode.Parse(childNode, this);
                    ChildNodes.Add(childBulletNode);
                }
            }
        }
        /// <summary>
        /// Parses a bulletml document into this bullet pattern
        /// </summary>
        /// <param name="xmlFileName">Xml file name.</param>
        public bool ParseXML(string xmlFileName)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing = DtdProcessing.Ignore;

            using (XmlReader reader = XmlReader.Create(xmlFileName, settings))
            {
                //Open the file.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode rootXmlNode = xmlDoc.DocumentElement;

                //make sure it is actually an xml node
                if (rootXmlNode.NodeType == XmlNodeType.Element)
                {
                    //eat up the name of that xml node
                    string strElementName = rootXmlNode.Name;
                    if (("bulletml" != strElementName) || !rootXmlNode.HasChildNodes)
                    {
                        //The first node HAS to be bulletml
                        Debug.Assert(false);
                        return(false);
                    }

                    //Create the root node of the bulletml tree
                    RootNode = new BulletMLNode();

                    //Read in the whole bulletml tree
                    if (!RootNode.Parse(rootXmlNode, null))
                    {
                        //an error ocurred reading in the tree
                        return(false);
                    }
                    Debug.Assert(ENodeName.bulletml == RootNode.Name);

                    //Find what kind of pattern this is: horizontal or vertical
                    XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                    for (int i = 0; i < mapAttributes.Count; i++)
                    {
                        //will only have the name attribute
                        string strName  = mapAttributes.Item(i).Name;
                        string strValue = mapAttributes.Item(i).Value;
                        if ("type" == strName)
                        {
                            //if  this is a top level node, "type" will be veritcal or horizontal
                            Orientation = StringToPatternType(strValue);
                        }
                    }
                }
                else
                {
                    //should be an xml node!!!
                    Debug.Assert(false);
                    return(false);
                }
            }

            //grab that filename
            Filename = xmlFileName;
            return(true);
        }
Example #8
0
        public void Initialize()
        {
            XmlDocument doc = new XmlDocument();

            string[] xmlFilesArray = Directory.GetFiles(@"data\xml\classes\");
            foreach (string i in xmlFilesArray)
            {
                doc.Load(i);

                XmlNodeList nodes = doc.DocumentElement?.SelectNodes("/list/class");

                if (nodes == null)
                {
                    continue;
                }

                foreach (XmlNode node in nodes)
                {
                    XmlElement ownerElement = node.Attributes?[0].OwnerElement;
                    if ((ownerElement == null) || (node.Attributes == null) || !"class".Equals(ownerElement.Name))
                    {
                        continue;
                    }

                    XmlNamedNodeMap attrs   = node.Attributes;
                    ClassId         classId = ClassId.Values.FirstOrDefault(x => ((int)x.Id).Equals(Convert.ToInt32(attrs.Item(0).Value)));
                    StatsSet        set     = new StatsSet();

                    for (XmlNode cd = node.FirstChild; cd != null; cd = cd.NextSibling)
                    {
                        if ((cd.NextSibling != null) && "set".Equals(cd.NextSibling.Name) && (cd.NextSibling != null))
                        {
                            attrs = cd.NextSibling.Attributes;
                            if (attrs == null)
                            {
                                continue;
                            }

                            string name  = attrs.GetNamedItem("name").Value;
                            string value = attrs.GetNamedItem("val").Value;
                            set.Set(name, value);
                        }
                        else
                        {
                            break;
                        }
                    }

                    PcTemplate pcTempl = new PcTemplate(classId, set);
                    Templates.Add((int)pcTempl.ClassId.Id, pcTempl);
                }
            }

            Log.Info($"CharTemplateTable: Loaded {Templates.Count} character templates.");
        }
Example #9
0
        /// <summary>
        /// Parse the specified bulletNodeElement.
        /// Read all the data from the xml node into this dude.
        /// </summary>
        /// <param name="bulletNodeElement">Bullet node element.</param>
        public bool Parse(XmlNode bulletNodeElement, BulletMLNode parentNode)
        {
            Debug.Assert(null != bulletNodeElement);

            //grab the parent node
            Parent = parentNode;

            //get the node type
            Name = BulletMLNode.StringToName(bulletNodeElement.Name);

            //Parse all our attributes
            XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes;

            for (int i = 0; i < mapAttributes.Count; i++)
            {
                string strName  = mapAttributes.Item(i).Name;
                string strValue = mapAttributes.Item(i).Value;

                if ("type" == strName)
                {
                    //skip the type attribute in top level nodes
                    if (ENodeName.bulletml == Name)
                    {
                        continue;
                    }

                    //get the bullet node type
                    NodeType = BulletMLNode.StringToType(strValue);
                }
                else if ("label" == strName)
                {
                    //label is just a text value
                    Label = strValue;
                }
            }

            //parse all the child nodes
            if (bulletNodeElement.HasChildNodes)
            {
                for (XmlNode childNode = bulletNodeElement.FirstChild;
                     null != childNode;
                     childNode = childNode.NextSibling)
                {
                    //if the child node is a text node, parse it into this dude
                    if (XmlNodeType.Text == childNode.NodeType)
                    {
                        //Get the text of the child xml node, but store it in THIS bullet node
                        NodeEquation.Parse(childNode.Value);
                        continue;
                    }

                    //create a new node
                    BulletMLNode childBulletNode = new BulletMLNode();

                    //read in the node
                    if (!childBulletNode.Parse(childNode, this))
                    {
                        return(false);
                    }

                    //store the node
                    ChildNodes.Add(childBulletNode);
                }
            }

            return(true);
        }
Example #10
0
        internal void ParseXmlStream(Stream xmlStream)
        {
            // initialise schema for validating the document
            if (schema == null)
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BulletMLLib.Content.bulletml.xsd"))
                {
                    if (stream == null)
                    {
                        throw new InvalidBulletPatternException("Could not find XML schema.");
                    }
                    schema = XmlSchema.Read(stream, null);
                }
            }

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing  = DtdProcessing.Ignore;
            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(schema);

            using (XmlReader reader = XmlReader.Create(xmlStream, settings))
            {
                try
                {
                    //Open the file.
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(reader);
                    XmlNode rootXmlNode = xmlDoc.DocumentElement;

                    //make sure it is actually an xml node
                    if (rootXmlNode.NodeType == XmlNodeType.Element)
                    {
                        //eat up the name of that xml node
                        string strElementName = rootXmlNode.Name;
                        if ("bulletml" != strElementName)
                        {
                            //The first node HAS to be bulletml
                            throw new InvalidBulletPatternException("Root XML element should be '<bulletml>'.");
                        }

                        //Create the root node of the bulletml tree
                        RootNode = new BulletMLNode(ENodeName.bulletml);

                        //Read in the whole bulletml tree
                        RootNode.Parse(rootXmlNode, null);

                        //Find what kind of pattern this is: horizontal or vertical
                        XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                        for (int i = 0; i < mapAttributes.Count; i++)
                        {
                            //will only have the name attribute
                            string strName  = mapAttributes.Item(i).Name;
                            string strValue = mapAttributes.Item(i).Value;
                            if ("type" == strName)
                            {
                                //if  this is a top level node, "type" will be veritcal or horizontal
                                Orientation = StringToPatternType(strValue);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //an error ocurred reading in the tree
                    throw new InvalidBulletPatternException("Could not read XML.", ex);
                }
            }

            //validate that the bullet nodes are all valid
            try
            {
                RootNode.ValidateNode();
            }
            catch (Exception ex)
            {
                //an error ocurred reading in the tree
                throw new InvalidBulletPatternException("XML did not validate.", ex);
            }
        }
Example #11
0
        public static void Initialize()
        {
            _templates = new Dictionary <int, PcTemplate>();

            XmlDocument doc = new XmlDocument();

            string[] xmlFilesArray = Directory.GetFiles(@"data\xml\classes\");
            foreach (string i in xmlFilesArray)
            {
                doc.Load(i);

                XmlNodeList nodes = doc.DocumentElement?.SelectNodes("/list/class");

                if (nodes == null)
                {
                    continue;
                }

                foreach (XmlNode node in nodes)
                {
                    XmlElement ownerElement = node.Attributes?[0].OwnerElement;
                    if (ownerElement == null || node.Attributes == null || ownerElement.Name != "class")
                    {
                        continue;
                    }

                    XmlNamedNodeMap attrs   = node.Attributes;
                    ClassId         classId = ClassId.Values.FirstOrDefault(x => (int)x.Id == Convert.ToInt32(attrs.Item(0).Value));
                    StatsSet        set     = new StatsSet();

                    for (XmlNode cd = node.FirstChild; cd?.NextSibling != null; cd = cd.NextSibling)
                    {
                        if (cd.NextSibling.Name == "set")
                        {
                            attrs = cd.NextSibling.Attributes;

                            if (attrs == null)
                            {
                                continue;
                            }

                            string name  = attrs.GetNamedItem("name").Value;
                            string value = attrs.GetNamedItem("val").Value;

                            set.Set(name, value);
                        }
                        else if (cd.NextSibling.Name == "items")
                        {
                            attrs = cd.NextSibling.Attributes;

                            if (attrs == null)
                            {
                                continue;
                            }

                            string value = attrs.GetNamedItem("val").Value;

                            set.Set("items", value);
                        }
                    }

                    PcTemplate pcTempl = new PcTemplate(classId, set);
                    _templates.Add((int)pcTempl.ClassId.Id, pcTempl);
                }
            }

            Log.Info($"Loaded {_templates.Count} character templates.");
        }
Example #12
0
        /// <summary>
        /// Parse the specified bulletNodeElement.
        /// Read all the data from the XML node into this node.
        /// </summary>
        /// <param name="bulletNodeElement">Bullet node element.</param>
        /// <param name="parentNode">Parent node element.</param>
        public virtual void Parse(XmlNode bulletNodeElement, BulletMLNode parentNode)
        {
            // Handle null argument.
            if (bulletNodeElement == null)
            {
                throw new ArgumentNullException(nameof(bulletNodeElement));
            }

            // Grab the parent node
            Parent = parentNode;

            // Parse all attributes except for the root node
            if (Parent != null)
            {
                XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes;

                if (mapAttributes != null)
                {
                    for (var i = 0; i < mapAttributes.Count; i++)
                    {
                        var strName  = mapAttributes.Item(i).Name;
                        var strValue = mapAttributes.Item(i).Value;

                        // Get the bullet node type
                        if (strName == AttributeName.type.ToString())
                        {
                            NodeType = StringToType(strValue);
                        }
                        // Label is just a text value
                        else if (strName == AttributeName.label.ToString())
                        {
                            Label = strValue;
                        }
                    }
                }
            }

            // Parse all the child nodes
            if (bulletNodeElement.HasChildNodes)
            {
                for (var childNode = bulletNodeElement.FirstChild;
                     childNode != null;
                     childNode = childNode.NextSibling)
                {
                    // Skip any comments in the bulletml script
                    if (childNode.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }

                    // If the child node is a text node, parse it into this bullet
                    if (childNode.NodeType == XmlNodeType.Text)
                    {
                        // Get the text of the child xml node, but store it in THIS bullet node
                        _nodeEquation.Parse(childNode.Value);
                        continue;
                    }

                    // Create a new node
                    var childBulletNode = NodeFactory.CreateNode(StringToName(childNode.Name));

                    // Read in the node and store it
                    childBulletNode.Parse(childNode, this);
                    ChildNodes.Add(childBulletNode);
                }
            }
        }
Example #13
0
        public SchemaElement(XmlNode eDef)
        {
            //attributes define this tag, so get them...
            XmlNamedNodeMap atts = eDef.Attributes;

            defNode       = eDef;
            parentDefNode = eDef.ParentNode;

            //physical tag name for this node
            tagName = eDef.Name;

            //get all the attributes and set the object instance variables.
            for (int i = 0; i < atts.Count; i++)
            {
                XmlNode thisAtt = atts.Item(i);
                if (thisAtt.Name.Equals(MINOCCURS))
                {
                    minOccurs = Int32.Parse(thisAtt.Value);
                }
                else if (thisAtt.Name.Equals(MAXOCCURS))
                {
                    if (thisAtt.Value.Equals(BLANK))
                    {
                        maxOccurs = UNBOUND;
                    }
                    else
                    {
                        maxOccurs = Int32.Parse(thisAtt.Value);
                    }
                }
                else if (thisAtt.Name.Equals(NAME))
                {
                    name = thisAtt.Value;
                    if (name.Equals(""))
                    {
                        name = eDef.Name.First().ToString().ToUpper() + eDef.Name.Substring(1);
                    }
                }
                else if (thisAtt.Name.Equals(TYPE))
                {
                    //StringTokenizer st = new StringTokenizer(thisAtt.Value, TYPE_DELIM);
                    string[] st = thisAtt.Value.Split(':');
                    if (st.Count() > 1)
                    {
                        type = st[0];
                    }
                    else
                    {
                        type = thisAtt.Value;
                    }
                }
                else if (thisAtt.Name.Equals(VOCAB))
                {
                    // StringTokenizer st = new StringTokenizer(thisAtt.Value, VOCAB_DELIM);
                    string[] st      = thisAtt.Value.Split(',');
                    int      numToks = st.Count();
                    vocab.Add("No Selection");
                    for (int j = 0; j < numToks; j++)
                    {
                        vocab.Add(st[j].Trim());
                    }
                    vocab.Add("Other");
                }
                else if (thisAtt.Name.Equals(SHOWTAG))
                {
                    if (thisAtt.Value.Equals("false"))
                    {
                        showTag = false;
                    }
                }
                else if (thisAtt.Name.Equals(ISSELECTABLE))
                {
                    if (thisAtt.Value.Equals("false"))
                    {
                        isSelectable = false;
                    }
                }
                else if (thisAtt.Name.Equals(REQUIREDVALUE))
                {
                    requiredValue = thisAtt.Value;
                    if (!requiredValue.Equals(""))
                    {
                        hasRequiredValue = true;
                    }
                }
            }
        } //end constructor
        /// <summary>
        /// Parses a bulletml document into this bullet pattern
        /// </summary>
        /// <param name="xmlFileName">Xml file name.</param>
        public void ParseXML(string xmlFileName)
        {
#if NETFX_CORE
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.DtdProcessing = DtdProcessing.Ignore;
#else
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ValidationType          = ValidationType.None;
            settings.DtdProcessing           = DtdProcessing.Parse;
            settings.ValidationEventHandler += new ValidationEventHandler(MyValidationEventHandler);
#endif
            try
            {
                using (XmlReader reader = XmlReader.Create(xmlFileName, settings))
                {
                    //Open the file.
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(reader);
                    XmlNode rootXmlNode = xmlDoc.DocumentElement;

                    //make sure it is actually an xml node
                    if (rootXmlNode.NodeType == XmlNodeType.Element)
                    {
                        //eat up the name of that xml node
                        string strElementName = rootXmlNode.Name;
                        if ("bulletml" != strElementName)
                        {
                            //The first node HAS to be bulletml
                            throw new Exception("Error reading \"" + xmlFileName + "\": XML root node needs to be \"bulletml\", found \"" + strElementName + "\" instead");
                        }

                        //Create the root node of the bulletml tree
                        RootNode = new BulletMLNode(ENodeName.bulletml);

                        //Read in the whole bulletml tree
                        RootNode.Parse(rootXmlNode, null);

                        //Find what kind of pattern this is: horizontal or vertical
                        XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                        for (int i = 0; i < mapAttributes.Count; i++)
                        {
                            //will only have the name attribute
                            string strName  = mapAttributes.Item(i).Name;
                            string strValue = mapAttributes.Item(i).Value;
                            if ("type" == strName)
                            {
                                //if  this is a top level node, "type" will be veritcal or horizontal
                                Orientation = StringToPatternType(strValue);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //an error ocurred reading in the tree
                throw new Exception("Error reading \"" + xmlFileName + "\"", ex);
            }

            //grab that filename
            Filename = xmlFileName;

            //validate that the bullet nodes are all valid
            try
            {
                RootNode.ValidateNode();
            }
            catch (Exception ex)
            {
                //an error ocurred reading in the tree
                throw new Exception("Error reading \"" + xmlFileName + "\"", ex);
            }
        }
Example #15
0
    public static void Main(string[] args)
    {
        List <string>    files     = new List <string>(args);
        HashSet <string> processed = new HashSet <string>();
        int count = files.Count;

        for (int i = 0; i < count; i++)
        {
            string filename = Path.GetRelativePath(Directory.GetCurrentDirectory(), files[i]);

            if (processed.Contains(filename))
            {
                Console.Error.WriteLine("SKIP {0}", filename);
                continue;
            }
            Console.Error.WriteLine("OPEN {0}", filename);
            processed.Add(filename);

            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(filename);
            }
            catch (XmlException x)
            {
                Console.Error.WriteLine("{0}:{1}:{2}:{3}", filename, "Exception", x.LineNumber, x.Message);
                continue;
            }

            XmlNamedNodeMap nMap      = doc.DocumentType.Entities;
            Uri             current   = new Uri(doc.BaseURI);
            string          localPath = Path.GetRelativePath(Directory.GetCurrentDirectory(), current.LocalPath);

            for (int j = 0; j < nMap.Count; j++)
            {
                XmlEntity ent     = (XmlEntity)nMap.Item(j);
                Uri       related = null;
                Uri.TryCreate(current, ent.SystemId, out related);
                if (related != null)
                {
                    string relatedPath = Path.GetRelativePath(Directory.GetCurrentDirectory(), related.LocalPath);
                    if (!processed.Contains(relatedPath))
                    {
                        files.Add(relatedPath);
                        count++;
                    }
                    Console.WriteLine("{0}:{1}:{2}:{3}", localPath, "EntityInclusion", ent.Name, relatedPath);
                    Console.Error.WriteLine("• {0}", String.Join(",", files));
                }
                else
                {
                    Console.WriteLine("{0}:{1}:{2}:{3}", localPath, "EntityDeclaration", ent.Name, ent.InnerText);
                }
            }

            XmlTextReader reader = null;

            try
            {
                reader = new XmlTextReader(filename);
                reader.WhitespaceHandling = WhitespaceHandling.None;

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.EntityReference:
                        Console.WriteLine("{0}:{1}:{2}:{3}", localPath, "EntityInclusion", reader.Name, "");
                        break;
                    }
                }
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
    }
Example #16
0
        public void Initialize()
        {
            XmlDocument doc = new XmlDocument();

            string[] xmlFilesArray = Directory.GetFiles(@"data\xml\classes\");
            for (int i = 0; i < xmlFilesArray.Length; i++)
            {
                doc.Load(xmlFilesArray[i]);
                XmlNodeList nodes = doc.DocumentElement.SelectNodes("/list/class");

                foreach (XmlNode node in nodes)
                {
                    if ("class".Equals(node.Attributes[0].OwnerElement.Name))
                    {
                        XmlNamedNodeMap attrs   = node.Attributes;
                        ClassId         classId = ClassId.Values.FirstOrDefault(x => ((int)x.Id).Equals(Convert.ToInt32(attrs.Item(0).Value)));
                        StatsSet        set     = new StatsSet();

                        for (XmlNode cd = node.FirstChild; cd != null; cd = cd.NextSibling)
                        {
                            if ("set".Equals(cd.NextSibling.Name) && cd.NextSibling != null)
                            {
                                attrs = cd.NextSibling.Attributes;
                                string name  = attrs.GetNamedItem("name").Value;
                                string value = attrs.GetNamedItem("val").Value;
                                set.Set(name, value);
                            }
                            else
                            {
                                break;
                            }
                        }
                        PcTemplate pcTempl = new PcTemplate(classId, set);
                        templates.Add((int)pcTempl.ClassId.Id, pcTempl);
                    }
                }
            }
            Log.Info($"Loaded { templates.Count } character templates.");
        }