/// <summary>
 /// Deletes the the extra span elments introduced by Word
 /// </summary>
 /// <param name="xmlDoc">A reference to the xml dom.</param>
 public void Filter(ref System.Xml.XmlDocument xmlDoc)
 {
     List<XmlNode> extraNodes = new List<XmlNode>();
     XmlNodeList nodes = xmlDoc.GetElementsByTagName("span");
     foreach (XmlNode node in nodes)
     {
         extraNodes.Add(node);
     }
     //in order to allow DOM changes we need to iterate trough a List<XmlNode> instead of a XmlNodeList
     try
     {
         foreach (XmlNode node in extraNodes)
         {
             if (node.Attributes.Count == 0)
             {
                 //copy the child elements to the parent
                 foreach (XmlNode childNode in node.ChildNodes)
                 {
                     node.ParentNode.AppendChild(childNode);
                 }
             }
             XmlNode parent = node.ParentNode;
             parent.RemoveChild(node);
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
Exemplo n.º 2
0
        public override List<Product> ExtractProducts(System.Windows.Forms.HtmlDocument document)
        {
            List<Product> products = new List<Product>();

            HtmlElementCollection tt = document.GetElementsByTagName("head");
            if (tt.Count == 1)
            {
                HtmlElement title = tt[0];
                //title.in
                String pattern = "\\{.*?\"middle\":\"([^\"]+)\".*?\"description\":\"([^\"]*)\"";
                MatchCollection matches = Regex.Matches(title.InnerHtml, pattern, RegexOptions.IgnoreCase);
                for (int i = 0; i < matches.Count; i++)
                {
                    Product prod = new Product();
                    prod.Name = matches[i].Groups[2].Value;
                    if (prod.Name == "") prod.Name = "- no name -";
                    products.Add(prod);

                    prod.Photos.Add(new Photo(matches[i].Groups[1].Value));
                }

            }

            return products;
        }
        /// <summary>
        /// Extracts the inline styles, optimizes CSS and adds CSS classes in the head section for current page
        /// </summary>
        /// <param name="xmlDoc">A reference to a XmlDocument instance.</param>
        public void Filter(ref System.Xml.XmlDocument xmlDoc)
        {
            XmlNode body = xmlDoc.GetElementsByTagName("body")[0];
            XmlNode head = xmlDoc.GetElementsByTagName("head")[0];
            if (head == null)
            {
                head = xmlDoc.CreateNode(XmlNodeType.Element, "head", xmlDoc.NamespaceURI);
                body.ParentNode.InsertBefore(head, body);
            }

            //step1: inline CSS for existing CSS classes and ids, for better manipulation at step2 and step3
            CSSUtil.InlineCSS(ref xmlDoc);

            //step2: convert all inlined style to CSS classes
            //(including, but not limited to, those generated at step1)
            body = CSSUtil.ConvertInlineStylesToCssClasses(body, ref xmlDoc, ref counter, ref cssClasses);

            //step3: optimize CSS by grouping selectors with the same properties
            cssClasses = CSSUtil.GroupCSSSelectors(cssClasses);

            InsertCssClassesInHeader(ref head, ref xmlDoc);
        }
Exemplo n.º 4
0
        private Scalar ParseSequenceLengthField(QName name, System.Xml.XmlElement sequence, bool optional, ParsingContext parent)
        {
            System.Xml.XmlNodeList lengthElements = sequence.GetElementsByTagName("length");

            if (lengthElements.Count == 0)
            {
                var implicitLength = new Scalar(Global.CreateImplicitName(name), FASTType.U32, Operator.Operator.NONE, ScalarValue.UNDEFINED, optional)
                                         {Dictionary = parent.Dictionary};
                return implicitLength;
            }

            var length = (System.Xml.XmlElement) lengthElements.Item(0);
            var context = new ParsingContext(length, parent);
            return (Scalar) sequenceLengthParser.Parse(length, optional, context);
        }
Exemplo n.º 5
0
        protected internal static QName GetTypeReference(System.Xml.XmlElement templateTag)
        {
            string typeRefNs = "";
            System.Xml.XmlNodeList typeReferenceTags = templateTag.GetElementsByTagName("typeRef");

            if (typeReferenceTags.Count > 0)
            {
                var messageRef = (System.Xml.XmlElement) typeReferenceTags.Item(0);
                string typeReference = messageRef.GetAttribute("name");
                if (messageRef.HasAttribute("ns"))
                    typeRefNs = messageRef.GetAttribute("ns");
                return new QName(typeReference, typeRefNs);
            }
            return Error.FastConstants.ANY_TYPE;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Build a new instance using  XML data
        /// </summary>
        /// <param name="enumeratedDataElement"></param>
        public HLAEnumeratedData(System.Xml.XmlElement enumeratedDataElement)
            : base(enumeratedDataElement)
        {
            Representation = enumeratedDataElement.GetAttribute("representation");
            RepresentationNotes = enumeratedDataElement.GetAttribute("representationNotes");
            Semantics = ReplaceNewLines(enumeratedDataElement.GetAttribute("semantics"));
            SemanticsNotes = enumeratedDataElement.GetAttribute("semanticsNotes");

            System.Xml.XmlNodeList nl = enumeratedDataElement.GetElementsByTagName("enumerator");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement enumeratorElement = (System.Xml.XmlElement)nl.Item(i);
                HLAEnumerator enumerator = new HLAEnumerator(enumeratorElement);
                enumerators.Add(enumerator);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fixedRecordDataElement"></param>
        public HLAFixedRecordData(System.Xml.XmlElement fixedRecordDataElement)
            : base(fixedRecordDataElement)
        {
            Encoding = fixedRecordDataElement.GetAttribute("encoding");
            EncodingNotes = fixedRecordDataElement.GetAttribute("encodingNotes");
            Semantics = ReplaceNewLines(fixedRecordDataElement.GetAttribute("semantics"));
            SemanticsNotes = fixedRecordDataElement.GetAttribute("semanticsNotes");

            System.Xml.XmlNodeList nl = fixedRecordDataElement.GetElementsByTagName("field");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement enumeratorElement = (System.Xml.XmlElement)nl.Item(i);
                HLARecordField field = new HLARecordField(enumeratorElement);
                fields.Add(field);
            }
        }
 /// <summary>
 /// Deletes the Word introduced attribute from the parent div
 /// </summary>
 /// <param name="xmlDoc">A reference to the xml dom.</param>
 public void Filter(ref System.Xml.XmlDocument xmlDoc)
 {
     XmlNodeList nodes = xmlDoc.GetElementsByTagName("div");
     foreach (XmlNode node in nodes)
     {
         if (node.ParentNode.Name == "body")
         {
             XmlAttribute attribute = node.Attributes["class"];
             if (attribute != null && attribute.Value == DEFAULT_ATTRIBUTE_VALUE)
             {
                 node.Attributes.Remove(attribute);
                 break;
             }
         }
     }
 }
Exemplo n.º 9
0
        public static List<instrument> Load(System.Xml.XmlElement parent)
        {
            var instrumentlist = parent.GetElementsByTagName("instrument");
               List<instrument> ret = new List<instrument>();
               foreach (System.Xml.XmlElement ele in instrumentlist)
               {
               instrument i = new instrument();
               i.mytype = (instrumentType)System.Enum.Parse(typeof(instrumentType), ele.GetAttribute("type"));
               i.ip = ele.GetAttribute("ip");
               i.port = int.Parse(ele.GetAttribute("port"));
               i.local = bool.Parse(ele.GetAttribute("local"));
               i.flat = bool.Parse(ele.GetAttribute("flat"));
               ret.Add(i);

               }
               return ret;
        }
Exemplo n.º 10
0
 protected override void ReadXml(object entity, System.Xml.XmlElement parent, IFormatProvider formatProvider, string localName, bool mandatory)
 {
     XmlNodeList nodes = parent.GetElementsByTagName(localName);
     if (nodes.Count > 0)
     {
         IList list = (IList)GetValue(entity);
         if (list == null)
         {
             list = (IList)Activator.CreateInstance(DataType);
             SetValue(entity, list);
         }
         foreach (XmlElement element in nodes)
         {
             object child = _Constructor.Invoke(null);
             foreach (XmlAspectMember xam in _Aspect)
                 xam.ReadXml(child, element, formatProvider);
             list.Add(child);
         }
     }
 }
Exemplo n.º 11
0
        public override List<Product> ExtractProducts(System.Windows.Forms.HtmlDocument document)
        {
            List<Product> products = new List<Product>();
            Product prod = new Product();

            prod.Name = default_name;

            foreach (HtmlElement meta in document.GetElementsByTagName("meta"))
            {
                if (meta.GetAttribute("name") == "title") prod.Name = meta.GetAttribute("content");
            }

            products.Add(prod);

            foreach (HtmlElement img in document.Images)
            {
                String src = Regex.Replace(img.GetAttribute("src"), "small|square", "big");
                prod.Photos.Add(new Photo(src));
            }

            return products;
        }
Exemplo n.º 12
0
        public static List<section> Load(System.Xml.XmlElement parent)
        {
            var elementList = parent.GetElementsByTagName("section");
            List<section> sections = new List<section>();
            foreach (System.Xml.XmlElement e in elementList)
            {
                section s = new section();
                s.name = e.GetAttribute("name");
                s.instrumentid = int.Parse(e.GetAttribute("instrumentID"));
                s.starttime = float.Parse(e.GetAttribute("startTime"));
                var notes = e.GetElementsByTagName("note");
                foreach(System.Xml.XmlElement n in notes)
                {
                    note nx = new note();
                    nx.pitch = n.GetAttribute("pitch");
                    nx.time = float.Parse(n.GetAttribute("time"));
                    nx.duration = float.Parse(n.GetAttribute("duration"));
                    s.notes.Add(nx);
                }
                sections.Add(s);

            }
            return sections;
        }
Exemplo n.º 13
0
 private void ShowPartite(System.Xml.XmlDocument doc)
 {
     Internal.Main.StatusString = "Elaborazione dei dati delle partite in corso...";
     listPartite.BeginUpdate();
     listPartite.Items.Clear();
     System.Xml.XmlNode root = doc.GetElementsByTagName("calendar")[0];
     Internal.Main.StatusBar.Value = 0;
     Internal.Main.StatusBar.Maximum = root.ChildNodes.Count * 7;
     foreach (System.Xml.XmlNode row in root.ChildNodes)
     {
         string[] line = new string[6];
         foreach (System.Xml.XmlNode e in row.ChildNodes)
         {
             switch (e.Name)
             {
                 case "round": line[0] = e.InnerText; break;
                 case "date_match": line[1] = e.InnerText; break;
                 case "home_team": line[2] = U(e.InnerText); break;
                 case "away_team": line[3] = U(e.InnerText); break;
                 case "home_score": line[4] = e.InnerText; break;
                 case "away_score": line[5] = e.InnerText; break;
             }
             if (Internal.Main.StatusBar.Value < Internal.Main.StatusBar.Maximum) Internal.Main.StatusBar.Value++;
         }
         if (line[0] == "FRIENDLY") line[0] = "Amichevole";
         else if (line[0].Length >= 3) line[0] = "Coppa";
         if (line[4] == "#") line[4] = "-";
         if (line[5] == "#") line[5] = "-";
         ListViewItem item = new ListViewItem(line);
         listPartite.Items.Add(item);
     }
     listPartite.EndUpdate();
     Internal.Main.StatusString = "Elaborazione dei dati delle partite terminato!";
     Internal.Main.StatusBar.Value = 0;
 }
Exemplo n.º 14
0
 private void parseReps(Segment segmentObject, System.Xml.XmlElement segmentElement, System.String fieldName, int fieldNum)
 {
     System.Xml.XmlNodeList reps = segmentElement.GetElementsByTagName(fieldName);
     for (int i = 0; i < reps.Count; i++)
     {
         parse(segmentObject.getField(fieldNum, i), (System.Xml.XmlElement) reps.Item(i));
     }
 }
Exemplo n.º 15
0
 /// <summary> Populates a Composite type by looping through it's children, finding corresponding 
 /// Elements among the children of the given Element, and calling parse(Type, Element) for
 /// each.
 /// </summary>
 private void parseComposite(Composite datatypeObject, System.Xml.XmlElement datatypeElement)
 {
     if (datatypeObject is GenericComposite)
     {
         //elements won't be named GenericComposite.x
         //UPGRADE_TODO: Method 'org.w3c.dom.Node.getChildNodes' was converted to 'System.Xml.XmlNode.ChildNodes' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
         System.Xml.XmlNodeList children = datatypeElement.ChildNodes;
         int compNum = 0;
         for (int i = 0; i < children.Count; i++)
         {
             if (System.Convert.ToInt16(children.Item(i).NodeType) == (short) System.Xml.XmlNodeType.Element)
             {
                 parse(datatypeObject.getComponent(compNum), (System.Xml.XmlElement) children.Item(i));
                 compNum++;
             }
         }
     }
     else
     {
         Type[] children = datatypeObject.Components;
         for (int i = 0; i < children.Length; i++)
         {
             System.Xml.XmlNodeList matchingElements = datatypeElement.GetElementsByTagName(makeElementName(datatypeObject, i + 1));
             if (matchingElements.Count > 0)
             {
                 parse(children[i], (System.Xml.XmlElement) matchingElements.Item(0)); //components don't repeat - use 1st
             }
         }
     }
 }
Exemplo n.º 16
0
            /// <summary>
            /// Extract the signature element from the specified signed document.
            /// </summary>
            /// <param name="signedDoc"></param>
            /// <returns></returns>
            public static System.Xml.XmlElement GetSignatureFromSignedDoc(System.Xml.XmlDocument signedDoc)
            {
                // Find the "Signature" node and create a new
                // XmlNodeList object.
                System.Xml.XmlNodeList nodeList = signedDoc.GetElementsByTagName("Signature");

                // Throw an exception if no signature was found.
                if (nodeList.Count <= 0)
                {
                    throw new System.Security.Cryptography.CryptographicException("Verification failed: No Signature was found in the document.");
                }

                // Supports one signature for
                // the entire XML document.  Throw an exception 
                // if more than one signature was found.
                if (nodeList.Count >= 2)
                {
                    throw new System.Security.Cryptography.CryptographicException("Verification failed: More that one signature was found for the document.");
                }

                return (System.Xml.XmlElement)nodeList[0];
            }
Exemplo n.º 17
0
 private void ShowClassifica(System.Xml.XmlDocument doc)
 {
     listClassifica.BeginUpdate();
     listClassifica.Items.Clear();
     System.Xml.XmlNode root = doc.GetElementsByTagName("standings")[0];
     Internal.Main.StatusBar.Value = 0;
     Internal.Main.StatusBar.Maximum = root.ChildNodes.Count * 10;
     Internal.Main.StatusString = T("Elaborazione della classifica in corso...");
     foreach (System.Xml.XmlNode row in root.ChildNodes)
     {
         string[] line = new string[11];
         foreach (System.Xml.XmlNode e in row.ChildNodes)
         {
             switch (e.Name)
             {
                 case "position": line[0] = e.InnerText; break;
                 case "club_name": line[1] = U(e.InnerText); break;
                 case "points": line[10] = e.InnerText; break;
                 case "played": line[2] = e.InnerText; break;
                 case "win": line[3] = e.InnerText; break;
                 case "draw": line[4] = e.InnerText; break;
                 case "loss": line[5] = e.InnerText; break;
                 case "pts_plus": line[6] = e.InnerText; break;
                 case "pts_minus": line[7] = e.InnerText; break;
                 case "bonus": line[9] = e.InnerText; break;
             }
             if (Internal.Main.StatusBar.Value < Internal.Main.StatusBar.Maximum) Internal.Main.StatusBar.Value++;
         }
         int diff = ((int)(System.Convert.ToInt32(line[6]) - System.Convert.ToInt32(line[7])));
         line[8] = diff.ToString();
         if (diff > 0) line[8] = "+" + line[8];
         ListViewItem item = new ListViewItem(line);
         listClassifica.Items.Add(item);
     }
     Internal.Main.StatusString = T("Elaborazione della classifica terminata!");
     Internal.Main.StatusBar.Value = 0;
     listClassifica.EndUpdate();
 }
Exemplo n.º 18
0
		/// <summary> Returns the first child element of the given parent that matches the given 
		/// tag name.  Returns null if no instance of the expected element is present.  
		/// </summary>
		private System.Xml.XmlElement getFirstElementByTagName(System.String name, System.Xml.XmlElement parent)
		{
			System.Xml.XmlNodeList nl = parent.GetElementsByTagName(name);
			System.Xml.XmlElement ret = null;
			if (nl.Count > 0)
			{
				ret = (System.Xml.XmlElement) nl.Item(0);
			}
			return ret;
		}
		protected override void LoadUserData(System.Xml.XmlElement node)
		{
			this.isLoading = true;
			for (int i = 0; i < this.camViews.Count; i++)
			{
				System.Xml.XmlNodeList camViewElemQuery = node.GetElementsByTagName("CamView_" + i);
				if (camViewElemQuery.Count == 0) continue;

				System.Xml.XmlElement camViewElem = camViewElemQuery[0] as System.Xml.XmlElement;
				this.camViews[i].LoadUserData(camViewElem);
			}
			for (int i = 0; i < this.objViews.Count; i++)
			{
				System.Xml.XmlNodeList objViewElemQuery = node.GetElementsByTagName("ObjInspector_" + i);
				if (objViewElemQuery.Count == 0) continue;

				System.Xml.XmlElement objViewElem = objViewElemQuery[0] as System.Xml.XmlElement;
				this.objViews[i].LoadUserData(objViewElem);
			}
			if (this.logView != null)
			{
				System.Xml.XmlNodeList logViewElemQuery = node.GetElementsByTagName("LogView_0");
				if (logViewElemQuery.Count > 0)
				{
					System.Xml.XmlElement logViewElem = logViewElemQuery[0] as System.Xml.XmlElement;
					this.logView.LoadUserData(logViewElem);
				}
			}
			if (this.sceneView != null)
			{
				System.Xml.XmlNodeList sceneViewElemQuery = node.GetElementsByTagName("SceneView_0");
				if (sceneViewElemQuery.Count > 0)
				{
					System.Xml.XmlElement sceneViewElem = sceneViewElemQuery[0] as System.Xml.XmlElement;
					this.sceneView.LoadUserData(sceneViewElem);
				}
			}
			this.isLoading = false;
		}
Exemplo n.º 20
0
Arquivo: util.cs Projeto: nobled/mono
    public static System.Xml.XmlNodeList getSubNodes(System.Xml.XmlElement node)
    {
// GHT alternative for GetElementsByTagName("*")
//       System.Collections.ArrayList nodeArrayList = new System.Collections.ArrayList ();
//       getAllNodesRecursively (node, nodeArrayList);
//       return new XmlNodeArrayList (nodeArrayList);
// GHT alternative for GetElementsByTagName("*")
       return node.GetElementsByTagName("*");
    }
    private bool TryGetOneNotePageInfos(System.Xml.XmlDocument xmlDocument, out Dictionary<string /*PageId*/, OneNotePageInfo> pageInfos)
    {
      pageInfos = new Dictionary<string, OneNotePageInfo>();

      if (xmlDocument != null)
      {
        System.Xml.XmlNodeList pageNodeList = xmlDocument.GetElementsByTagName("one:Page");
        foreach (System.Xml.XmlNode pageNode in pageNodeList)
        {
          try
          {
            string pageUniqueId = pageNode.Attributes["ID"].Value;
            string parentNodeName = pageNode.ParentNode.Name;

            if (parentNodeName == "one:Section")
            {
              bool isDeletedPages = CheckIfDeleted(pageNode);
              // To avoid the situation that it is going to delete the pages that shouldn't be deleted and to keep the pages in the 'trash' folder.
              if (isDeletedPages == false)
              {
                if (pageInfos.ContainsKey(pageUniqueId) == false)
                {
                  // 'ID', 'path' and 'name' attributes are always existing.
                  string sectionId = pageNode.ParentNode.Attributes["ID"].Value;
                  string sectionPath = pageNode.ParentNode.Attributes["path"].Value;
                  string sectionName = pageNode.ParentNode.Attributes["name"].Value;

                  OneNotePageInfo pageInfo = new OneNotePageInfo();
                  pageInfo.ParentSectionId = sectionId;
                  pageInfo.ParentSectionFilePath = sectionPath;
                  pageInfo.ParentSectionName = sectionName;
                  pageInfo.PageName = pageNode.Attributes["name"].Value;
                  pageInfos.Add(pageUniqueId, pageInfo);
                }
              }
            }
          }
          catch (System.Exception exception)
          {
            etc.LoggerHelper.LogWarn("Ignore the exception: {0}", exception.ToString());
          }
        }
        return true;
      }
      else
      {
        etc.LoggerHelper.LogWarn("xmlDocument is null");
        return false;
      }
    }
Exemplo n.º 22
0
        public void ShowMultiKeyDialog(System.Xml.XmlElement xmlKeyRing)
        {
            this.cmbSecretKeys.Items.Clear();
            this.cmbSecretKeys.Enabled = true;

            XmlNodeList xnlSecretKeys = xmlKeyRing.GetElementsByTagName("SecretKey");
            IEnumerator ieKeys = xnlSecretKeys.GetEnumerator();
            while (ieKeys.MoveNext()) {
                XmlElement xmlKey = (XmlElement)ieKeys.Current;

                ComboBoxKeyItem cbkiKey = new ComboBoxKeyItem(xmlKey);
                cmbSecretKeys.Items.Add(cbkiKey);
            }

            cmbSecretKeys.SelectedIndex = 0;

            this.ShowDialog();
        }
Exemplo n.º 23
0
        protected override void LoadUserData(System.Xml.XmlElement node)
        {
            this.isLoading = true;
            for (int i = 0; i < this.camViews.Count; i++)
            {
                System.Xml.XmlNodeList camViewElemQuery = node.GetElementsByTagName("CamView_" + i);
                if (camViewElemQuery.Count == 0) continue;

                System.Xml.XmlElement camViewElem = camViewElemQuery[0] as System.Xml.XmlElement;
                this.camViews[i].LoadUserData(camViewElem);
            }
            this.isLoading = false;
        }
Exemplo n.º 24
0
		/// <summary> Populates a Composite type by looping through it's children, finding corresponding 
		/// Elements among the children of the given Element, and calling parse(Type, Element) for
		/// each.
		/// </summary>
		private void  parseComposite(Composite datatypeObject, System.Xml.XmlElement datatypeElement)
		{
			if (datatypeObject is GenericComposite)
			{
				//elements won't be named GenericComposite.x
				System.Xml.XmlNodeList children = datatypeElement.ChildNodes;
				int compNum = 0;
				for (int i = 0; i < children.Count; i++)
				{
					if (System.Convert.ToInt16(children.Item(i).NodeType) == (short) System.Xml.XmlNodeType.Element)
					{
						parse(datatypeObject.getComponent(compNum), (System.Xml.XmlElement) children.Item(i));
						compNum++;
					}
				}
			}
			else
			{
				Type[] children = datatypeObject.Components;
				for (int i = 0; i < children.Length; i++)
				{
					System.Xml.XmlNodeList matchingElements = datatypeElement.GetElementsByTagName(makeElementName(datatypeObject, i + 1));
					if (matchingElements.Count > 0)
					{
						parse(children[i], (System.Xml.XmlElement) matchingElements.Item(0)); //components don't repeat - use 1st
					}
				}
			}
		}