Search Results

Search found 83 results on 4 pages for 'selectnodes'.

Page 1/4 | 1 2 3 4  | Next Page >

  • HtmlAgilityPack SelectNodes expression to ignore an element with a certain attribute

    - by thaky
    I am trying to select nodes except from script nodes and a ul that has a class called 'relativeNav'. Can someone please direct me to the right path? I have been searching for this for a week and I can't find it anywhere. Currently I have this but it obviously selecting the //ul[@class='relativeNav'] as well. Is there anyway to put an NOT expression of it so that SelectNode will ignore that one? foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//body//*[not(self::script)]/text()")) { Console.WriteLine("Node: " + node); singleString += node.InnerText.Trim() + "\n"; }

    Read the article

  • Need help with Xpath methods in javascript (selectSingleNode, selectNodes)

    - by Andrija
    I want to optimize my javascript but I ran into a bit of trouble. I'm using XSLT transformation and the basic idea is to get a part of the XML and subquery it so the calls are faster and less expensive. This is a part of the XML: <suite> <table id="spis" runat="client"> <rows> <row id="spis_1"> <dispatch>'2008', '288627'</dispatch> <data col="urGod"> <title>2008</title> <description>Ur. god.</description> </data> <data col="rbr"> <title>288627</title> <description>Rbr.</description> </data> ... </rows> </table> </suite> In the page, this is the javascript that works with this: // this is my global variable for getting the elements so I just get the most // I can in one call elemCollection = iDom3.Table.all["spis"].XML.DOM.selectNodes("/suite/table/rows/row").context; //then I have the method that uses this by getting the subresults from elemCollection //rest of the method isn't interesting, only the selectNodes call _buildResults = function (){ var _RowList = elemCollection.selectNodes("/data[@col = 'urGod']/title"); var tmpResult = ['']; var substringResult=""; for (i=0; i<_RowList.length; i++) { tmpResult.push(_RowList[i].text,iDom3.Global.Delimiter); } ... //this variant works elemCollection = iDom3.Table.all["spis"].XML.DOM _buildResults = function (){ var _RowList = elemCollection.selectNodes("/suite/table/rows/row/data[@col = 'urGod']/title"); var tmpResult = ['']; var substringResult=""; for (i=0; i<_RowList.length; i++) { tmpResult.push(_RowList[i].text,iDom3.Global.Delimiter); } ... The problem is, I can't find a way to use the subresults to get what I need.

    Read the article

  • XmlDocument SelectNodes(Xpath): Order of result

    - by crauscher
    This is an example xml from MSDN <?xml version="1.0"?> <!-- A fragment of a book store inventory database --> <bookstore xmlns:bk="urn:samples"> <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8"> <title>Pride And Prejudice</title> </book> <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1"> <title>The Handmaid's Tale</title> </book> <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6"> <title>Emma</title> </book> <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3"> <title>Sense and Sensibility</title> </book> </bookstore> When I select all book nodes using the following code, which order will these nodes have? XmlDocument doc = new XmlDocument(); doc.Load("booksort.xml"); var nodeList =doc.SelectNodes("bookstore/book"); Will the order of the items in the nodelist be the same as the order in the xml? Is this order guaranteed?

    Read the article

  • Why does XPath.selectNodes(context) always use the whole document in JDOM

    - by Simeon
    Hi, I'm trying to run the same query on several different contexts, but I always get the same result. This is an example xml: <root> <p> <r> <t>text</t> </r> </p> <t>text2</t> </root> So this is what I'm doing: final XPath xpath = XPath.newInstance("//t"); List<Element> result = xpath.selectNodes(thisIsThePelement); // and I've debuged it, it really is the <p> element And I always get both <t> elements in the result list. I need just the <t> inside the <p> I'm passing to the XPath object. Any ideas would be of great help, thanks.

    Read the article

  • XmlNode.SelectNode with multiple attribute.

    - by kapil
    One of my nodes inmy xml file is as follows. <LOGIN_ID NAME="Kapil"> <SEARCH_ID>Kapil Koli</SEARCH_ID> <GUID>111</GUID> <FIRST_NAME>Kapil</FIRST_NAME> <LAST_NAME>Koli</LAST_NAME> <EMAIL_ID>[email protected]</EMAIL_ID> <PASSWORD>abc123**</PASSWORD> </LOGIN_ID> The code I am using is - XmlDocument document = new XmlDocument(); document.Load(_XmlFileName); nodeList = document.SelectNode."USERS/LOGIN_ID[contains(SEARCH_ID,'Kapil')"; nodeList = document.SelectNode."USERS/LOGIN_ID[contains(EMAIL_ID,'[email protected]')"; I want to use select node which will accept search_id and login_id as attributes to search? If either search_id or email_id is wrong, I want to return null. How could I do this? thanks. kapil.

    Read the article

  • Managing common code on Windows 7 (.NET) and Windows 8 (WinRT)

    - by ryanabr
    Recent announcements regarding Windows Phone 8 and the fact that it will have the WinRT behind it might make some of this less painful but I  discovered the "XmlDocument" object is in a new location in WinRT and is almost the same as it's brother in .NET System.Xml.XmlDocument (.NET) Windows.Data.Xml.Dom.XmlDocument (WinRT) The problem I am trying to solve is how to work with both types in the code that performs the same task on both Windows Phone 7 and Windows 8 platforms. The first thing I did was define my own XmlNode and XmlNodeList classes that wrap the actual Microsoft objects so that by using the "#if" compiler directive either work with the WinRT version of the type, or the .NET version from the calling code easily. public class XmlNode     { #if WIN8         public Windows.Data.Xml.Dom.IXmlNode Node { get; set; }         public XmlNode(Windows.Data.Xml.Dom.IXmlNode xmlNode)         {             Node = xmlNode;         } #endif #if !WIN8 public System.Xml.XmlNode Node { get; set ; } public XmlNode(System.Xml.XmlNode xmlNode)         {             Node = xmlNode;         } #endif     } public class XmlNodeList     { #if WIN8         public Windows.Data.Xml.Dom.XmlNodeList List { get; set; }         public int Count {get {return (int)List.Count;}}         public XmlNodeList(Windows.Data.Xml.Dom.XmlNodeList list)         {             List = list;         } #endif #if !WIN8 public System.Xml.XmlNodeList List { get; set ; } public int Count { get { return List.Count;}} public XmlNodeList(System.Xml.XmlNodeList list)         {             List = list;        } #endif     } From there I can then use my XmlNode and XmlNodeList in the calling code with out having to clutter the code with all of the additional #if switches. The challenge after this was the code that worked directly with the XMLDocument object needed to be seperate on both platforms since the method for populating the XmlDocument object is completly different on both platforms. To solve this issue. I made partial classes, one partial class for .NET and one for WinRT. Both projects have Links to the Partial Class that contains the code that is the same for the majority of the class, and the partial class contains the code that is unique to the version of the XmlDocument. The files with the little arrow in the lower left corner denotes 'linked files' and are shared in multiple projects but only exist in one location in source control. You can see that the _Win7 partial class is included directly in the project since it include code that is only for the .NET platform, where as it's cousin the _Win8 (not pictured above) has all of the code specific to the _Win8 platform. In the _Win7 partial class is this code: public partial class WUndergroundViewModel     { public static WUndergroundData GetWeatherData( double lat, double lng)         { WUndergroundData data = new WUndergroundData();             System.Net. WebClient c = new System.Net. WebClient(); string req = "http://api.wunderground.com/api/xxx/yesterday/conditions/forecast/q/[LAT],[LNG].xml" ;             req = req.Replace( "[LAT]" , lat.ToString());             req = req.Replace( "[LNG]" , lng.ToString()); XmlDocument doc = new XmlDocument();             doc.Load(c.OpenRead(req)); foreach (XmlNode item in doc.SelectNodes("/response/features/feature" ))             { switch (item.Node.InnerText)                 { case "yesterday" :                         ParseForecast( new FishingControls.XmlNodeList (doc.SelectNodes( "/response/forecast/txt_forecast/forecastdays/forecastday" )), new FishingControls.XmlNodeList (doc.SelectNodes( "/response/forecast/simpleforecast/forecastdays/forecastday" )), data); break ; case "conditions" :                         ParseCurrent( new FishingControls.XmlNode (doc.SelectSingleNode("/response/current_observation" )), data); break ; case "forecast" :                         ParseYesterday( new FishingControls.XmlNodeList (doc.SelectNodes( "/response/history/observations/observation" )),data); break ;                 }             } return data;         }     } in _win8 partial class is this code: public partial class WUndergroundViewModel     { public async static Task< WUndergroundData > GetWeatherData(double lat, double lng)         { WUndergroundData data = new WUndergroundData (); HttpClient c = new HttpClient (); string req = "http://api.wunderground.com/api/xxxx/yesterday/conditions/forecast/q/[LAT],[LNG].xml" ;             req = req.Replace( "[LAT]" , lat.ToString());             req = req.Replace( "[LNG]" , lng.ToString()); HttpResponseMessage msg = await c.GetAsync(req); string stream = await msg.Content.ReadAsStringAsync(); XmlDocument doc = new XmlDocument ();             doc.LoadXml(stream, null); foreach ( IXmlNode item in doc.SelectNodes("/response/features/feature" ))             { switch (item.InnerText)                 { case "yesterday" :                         ParseForecast( new FishingControls.XmlNodeList (doc.SelectNodes( "/response/forecast/txt_forecast/forecastdays/forecastday" )), new FishingControls.XmlNodeList (doc.SelectNodes( "/response/forecast/simpleforecast/forecastdays/forecastday" )), data); break; case "conditions" :                         ParseCurrent( new FishingControls.XmlNode (doc.SelectSingleNode("/response/current_observation" )), data); break; case "forecast" :                         ParseYesterday( new FishingControls.XmlNodeList (doc.SelectNodes( "/response/history/observations/observation")), data); break;                 }             } return data;         }     } Summary: This method allows me to have common 'business' code for both platforms that is pretty clean, and I manage the technology differences separately. Thank you tostringtheory for your suggestion, I was considering that approach.

    Read the article

  • PHP5 : Applying a method from an extended class on an object from the original (parent) class.

    - by Glauber Rocha
    Hello, I'm trying to extend two native PHP5 classes (DOMDocument and DOMNode) to implement 2 methods (selectNodes and selectSingleNode) in order to make XPath queries easier. I thought it would be rather straighforward, but I'm stuck in a problem which I think is an OOP beginner's issue. class nDOMDocument extends DOMDocument { public function selectNodes($xpath){ $oxpath = new DOMXPath($this); return $oxpath->query($xpath); } public function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } Then I tried to do extend DOMNode to implement the same methods so I can perform an XPath query directly on a node: class nDOMNode extends DOMNode { public function selectNodes($xpath){ $oxpath = new DOMXPath($this->ownerDocument,$this); return $oxpath->query($xpath); } public function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } Now if I execute the following code (on an arbitrary XMLDocument): $xmlDoc = new nDOMDocument; $xmlDoc->loadXML(...some XML...); $node1 = $xmlDoc->selectSingleNode("//item[@id=2]"); $node2 = $node1->selectSingleNode("firstname"); The third line works and returns a DOMNode object $node1. However, the fourth line doesn't work because the selectSingleNode method belongs to the nDOMNode class, not DOMNode. So my question: is there a way at some point to "transform" the returned DOMNode object into a nDOMNode object? I feel I'm missing some essential point here and I'd greatly appreciate your help. (Sorry, this is a restatement of my question http://stackoverflow.com/questions/2573820/)

    Read the article

  • Can this be imporved? Scrubing of dangerous html tags.

    - by chobo2
    Hi I been finding that for something that I consider pretty import there is very little information or libraries on how to deal with this problem. I found this while searching. I really don't know all the million ways that a hacker could try to insert the dangerous tags. I have a rich html editor so I need to keep non dangerous tags but strip out bad ones. So is this script missing anything? It uses html agility pack. public string ScrubHTML(string html) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); //Remove potentially harmful elements HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//script|//link|//iframe|//frameset|//frame|//applet|//object|//embed"); if (nc != null) { foreach (HtmlNode node in nc) { node.ParentNode.RemoveChild(node, false); } } //remove hrefs to java/j/vbscript URLs nc = doc.DocumentNode.SelectNodes("//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.SetAttributeValue("href", "#"); } } //remove img with refs to java/j/vbscript URLs nc = doc.DocumentNode.SelectNodes("//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.SetAttributeValue("src", "#"); } } //remove on<Event> handlers from all tags nc = doc.DocumentNode.SelectNodes("//*[@onclick or @onmouseover or @onfocus or @onblur or @onmouseout or @ondoubleclick or @onload or @onunload]"); if (nc != null) { foreach (HtmlNode node in nc) { node.Attributes.Remove("onFocus"); node.Attributes.Remove("onBlur"); node.Attributes.Remove("onClick"); node.Attributes.Remove("onMouseOver"); node.Attributes.Remove("onMouseOut"); node.Attributes.Remove("onDoubleClick"); node.Attributes.Remove("onLoad"); node.Attributes.Remove("onUnload"); } } // remove any style attributes that contain the word expression (IE evaluates this as script) nc = doc.DocumentNode.SelectNodes("//*[contains(translate(@style, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'expression')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.Attributes.Remove("stYle"); } } return doc.DocumentNode.WriteTo(); }

    Read the article

  • Can this be improved? Scrubing of dangerous html tags.

    - by chobo2
    I been finding that for something that I consider pretty import there is very little information or libraries on how to deal with this problem. I found this while searching. I really don't know all the million ways that a hacker could try to insert the dangerous tags. I have a rich html editor so I need to keep non dangerous tags but strip out bad ones. So is this script missing anything? It uses html agility pack. public string ScrubHTML(string html) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); //Remove potentially harmful elements HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//script|//link|//iframe|//frameset|//frame|//applet|//object|//embed"); if (nc != null) { foreach (HtmlNode node in nc) { node.ParentNode.RemoveChild(node, false); } } //remove hrefs to java/j/vbscript URLs nc = doc.DocumentNode.SelectNodes("//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.SetAttributeValue("href", "#"); } } //remove img with refs to java/j/vbscript URLs nc = doc.DocumentNode.SelectNodes("//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.SetAttributeValue("src", "#"); } } //remove on<Event> handlers from all tags nc = doc.DocumentNode.SelectNodes("//*[@onclick or @onmouseover or @onfocus or @onblur or @onmouseout or @ondoubleclick or @onload or @onunload]"); if (nc != null) { foreach (HtmlNode node in nc) { node.Attributes.Remove("onFocus"); node.Attributes.Remove("onBlur"); node.Attributes.Remove("onClick"); node.Attributes.Remove("onMouseOver"); node.Attributes.Remove("onMouseOut"); node.Attributes.Remove("onDoubleClick"); node.Attributes.Remove("onLoad"); node.Attributes.Remove("onUnload"); } } // remove any style attributes that contain the word expression (IE evaluates this as script) nc = doc.DocumentNode.SelectNodes("//*[contains(translate(@style, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'expression')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.Attributes.Remove("stYle"); } } return doc.DocumentNode.WriteTo(); }

    Read the article

  • TCL tDom Empty XML Tag

    - by pws5068
    I'm using tDom to loop through some XML and pull out each element's text(). set xml { <systems> <object> <type>Hardware</type> <name>Server Name</name> <attributes> <vendor></vendor> </attributes> </object> <object> <type>Hardware</type> <name>Server Two Name</name> <attributes> <vendor></vendor> </attributes> </object> </systems> }; set doc [dom parse $xml] set root [$doc documentElement] set nodeList [$root selectNodes /systems/object] foreach node $nodeList { set nType [$node selectNodes type/text()] set nName [$node selectNodes name/text()] set nVendor [$node selectNodes attributes/vendor/text()] # Etc... puts "Type: " puts [$nType data] # Etc .. puts [$nVendor data] } But when it tries to print out the Vendor, which is empty, it thows the error invalid command name "". How can I ignore this and just set $nVendor to an empty string?

    Read the article

  • Select only items in a specific DIV using HtmlAgilityPack

    - by Adam Haile
    I'm trying to use the HtmlAgilityPack to pull all of the links from a page that are contained within a div declared as <div class='content'> However, when I use the code below I simply get ALL links on the entire page. This doesn't really make sense to me since I am calling SelectNodes from the sub-node I selected earlier (which when viewed in the debugger only shows the HTML from that specific div). So, it's like it's going back to the very root node every time I call SelectNodes. The code I use is below: HtmlWeb hw = new HtmlWeb(); HtmlDocument doc = hw.Load(@"http://example.com"); HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@class='content']"); foreach(HtmlNode link in node.SelectNodes("//a[@href]")) { Console.WriteLine(link.Value); } Is this the expected behavior? And if so, how do I get it to do what I'm expecting?

    Read the article

  • Get Links in class with html agility pack

    - by acidzombie24
    There are a bunch of tr's with the class alt. I want to get all the links (or the first of last) yet i cant figure out how with html agility pack. I tried variants of a but i only get all the links or none. It doesnt seem to only get the one in the node which makes no sense since i am writing n.SelectNodes html.LoadHtml(page); var nS = html.DocumentNode.SelectNodes("//tr[@class='alt']"); foreach (var n in nS) { var aS = n.SelectNodes("a"); ... }

    Read the article

  • Can this be improved? Scrubbing of dangerous html tags.

    - by chobo2
    I been finding that for something that I consider pretty import there is very little information or libraries on how to deal with this problem. I found this while searching. I really don't know all the million ways that a hacker could try to insert the dangerous tags. I have a rich html editor so I need to keep non dangerous tags but strip out bad ones. So is this script missing anything? It uses html agility pack. public string ScrubHTML(string html) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); //Remove potentially harmful elements HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//script|//link|//iframe|//frameset|//frame|//applet|//object|//embed"); if (nc != null) { foreach (HtmlNode node in nc) { node.ParentNode.RemoveChild(node, false); } } //remove hrefs to java/j/vbscript URLs nc = doc.DocumentNode.SelectNodes("//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.SetAttributeValue("href", "#"); } } //remove img with refs to java/j/vbscript URLs nc = doc.DocumentNode.SelectNodes("//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.SetAttributeValue("src", "#"); } } //remove on<Event> handlers from all tags nc = doc.DocumentNode.SelectNodes("//*[@onclick or @onmouseover or @onfocus or @onblur or @onmouseout or @ondoubleclick or @onload or @onunload]"); if (nc != null) { foreach (HtmlNode node in nc) { node.Attributes.Remove("onFocus"); node.Attributes.Remove("onBlur"); node.Attributes.Remove("onClick"); node.Attributes.Remove("onMouseOver"); node.Attributes.Remove("onMouseOut"); node.Attributes.Remove("onDoubleClick"); node.Attributes.Remove("onLoad"); node.Attributes.Remove("onUnload"); } } // remove any style attributes that contain the word expression (IE evaluates this as script) nc = doc.DocumentNode.SelectNodes("//*[contains(translate(@style, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'expression')]"); if (nc != null) { foreach (HtmlNode node in nc) { node.Attributes.Remove("stYle"); } } return doc.DocumentNode.WriteTo(); } Edit 2 people have suggested whitelisting. I actually like the idea of whitelisting but never actually did it because no one can actually tell me how to do it in C# and I can't even really find tutorials for how to do it in c#(the last time I looked. I will check it out again). How do you make a white list? Is it just a list collection? How do you actual parse out all html tags, script tags and every other tag? Once you have the tags how do you determine which ones are allowed? Compare them to you list collection? But what happens if the content is coming in and has like 100 tags and you have 50 allowed. You got to compare each of those 100 tag by 50 allowed tags. Thats quite a bit to go through and could be slow. Once you found a invalid tag how do you remove it? I don't really want to reject a whole set of text if one tag was found to be invalid. I rather remove and insert the rest. Should I be using html agility pack?

    Read the article

  • Parsing HTML using HTTP Agility Pack

    - by Pajci
    Here is one table out of 5: <h3>marec - maj 2009</h3> <div class="graf_table"> <table summary="layout table"> <tr> <th>DATUM</th> <td class="datum">10.03.2009</td> <td class="datum">24.03.2009</td> <td class="datum">07.04.2009</td> <td class="datum">21.04.2009</td> <td class="datum">05.05.2009</td> <td class="datum">06.05.2009</td> </tr> <tr> <th>Maloprodajna cena [EUR/L]</th> <td>0,96000</td> <td>0,97000</td> <td>0,99600</td> <td>1,00800</td> <td>1,00800</td> <td>1,01000</td> </tr> <tr> <th>Maloprodajna cena [SIT/L]</th> <td>230,054</td> <td>232,451</td> <td>238,681</td> <td>241,557</td> <td>241,557</td> <td>242,036</td> </tr> <tr> <th>Prodajna cena brez dajatev</th> <td>0,33795</td> <td>0,34628</td> <td>0,36795</td> <td>0,37795</td> <td>0,37795</td> <td>0,37962</td> </tr> <tr> <th>Trošarina</th> <td>0,46205</td> <td>0,46205</td> <td>0,46205</td> <td>0,46205</td> <td>0,46205</td> <td>0,46205</td> </tr> <tr> <th>DDV</th> <td>0,16000</td> <td>0,16167</td> <td>0,16600</td> <td>0,16800</td> <td>0,16800</td> <td>0,16833</td> </tr> </table> </div> I have to extract out values, where table header is DATUM and Maloprodajna cena [EUR/L]. I am using Agility HTML pack. this.htmlDoc = new HtmlAgilityPack.HtmlDocument(); this.htmlDoc.OptionCheckSyntax = true; this.htmlDoc.OptionFixNestedTags = true; this.htmlDoc.OptionAutoCloseOnEnd = true; this.htmlDoc.OptionOutputAsXml = true; // is this necessary ?? this.htmlDoc.OptionDefaultStreamEncoding = System.Text.Encoding.Default; I had a lot of trouble with getting those values out. I started with: var query = from html in doc.DocumentNode.SelectNodes("//div[@class='graf_table']").Cast<HtmlNode>() from table in html.SelectNodes("//table").Cast<HtmlNode>() from row in table.SelectNodes("tr").Cast<HtmlNode>() from cell in row.SelectNodes("th|td").Cast<HtmlNode>() select new { Table = table.Id, CellText = cell.InnerHtml }; but could not figure out a way to select only values where table header is DATUM and Maloprodajna cena[EUR/L]. Is it possible to do that with where clause? Then I ended with those two queries: var date = (from d in htmlDoc.DocumentNode.SelectNodes("//div[@class='graf_table']//table//tr[1]/td") select DateTime.Parse(d.InnerText)).ToArray(); var price = (from p in htmlDoc.DocumentNode.SelectNodes("//div[@class='graf_table']//table//tr[2]/td") select double.Parse(p.InnerText)).ToArray(); Is it possible to combine those two queries? And how would I convert that to lambda expression? I just started to learn those things and I would like to know how it is done so that in the future I would not have those question. O, one more question ... does anybody know any graph control, cause I have to show those values in graph. I started with Microsoft Chart Controls, but I am having trouble with setting it. So if anyone has any experience with it I would like to know how to set it, so that x axle will show all values not every second ... example: if I have: 10.03.2009, 24.03.2009, 07.04.2009, 21.04.2009, 05.05.2009, 06.05.2009 it show only: 10.03.2009, 07.04.2009, 05.05.2009, ect. I bind data to graph like that: chart1.Series["Series1"].Points.DataBindXY(date, price); I lot of questions for my fist post ... hehe, hope that I was not indistinct or something. Thank's for any reply!

    Read the article

  • xpath evaluting error in andorid

    - by R_Dhorawat
    i'm running one application in android browser which contain the following code.. [ if (typeof XPathResult != "undefined") { //use build in xpath support for Safari 3.0 //alert("xpathExpr"+xpathExpr); //alert("doc"+doc); var xmlDocument = doc; if (doc.nodeType != 9) { xmlDocument = doc.ownerDocument; } results = xmlDocument.evaluate(xpathExpr,doc, function(prefix) { return namespaces[prefix] || null;}, XPathResult.ANY_TYPE, null ); var thisResult; result = []; var len = 0; do { thisResult = results.iterateNext(); if (thisResult) { result[len] = thisResult; len++; } } while ( thisResult ); } else { try{ if (doc.selectNodes) { result = doc.selectNodes(xpathExpr); } }catch(ex){} } return result; ] but when i run this app in Firefox control come in if statement and everything works fine.. but in android browser it's giving error ... XPathResult undefined... this time control come to else statement and even here it's showing that selectNodes is undefind and. so the result come as null whereas in Firefox it's giving list of nodes.. realy need it to be done ... help needed.. thanks...

    Read the article

  • Xml Conversion "Type mismatch" Error

    - by prema
    I am selecting a query in sql server 2005 SELECT 'Region' AS ELEMENT,(SELECT GeographyName,GeoID from @tmpTable FOR XML RAW, TYPE) FOR XML RAW('Root') This will give the output in xml as <Root ELEMENT="Region"> <row GeographyName="East" GeoID="2" /> <row GeographyName="West" GeoID="3" /> <row GeographyName="North" GeoID="4" /> <row GeographyName="South" GeoID="5" /> </Root> In aspx page, i want to get this function Populatedata(obj, val) { var xmlDom = new JXmlDom(obj, false); --> at this point i am getting error var nodeHeader = xmlDom.selectNodes("//row"); // my code goes here } function JXmlDom (xml,isFile) { this.load=load; this.loadXML=loadXML; this.selectNodes=selectNodes; this.text=text; this.selectSingleNode=selectSingleNode; this.documentElement=documentElement; this.transformNode=transformNode; if (isFile) { this.dom=this.load (xml); }else { this.dom=this.loadXML (xml); } function loadXML (xml) { if (window.ActiveXObject) { var dom=new ActiveXObject("Microsoft.XMLDOm"); dom.async=false; dom.loadXML (xml); } if (document.implementation && document.implementation.createDocument) { var domParser=new DOMParser(); var dom=domParser.parseFromString (xml,"text/xml"); } return dom; } But when i am calling this i am getting an error as Type mismatch.Can anyone help me

    Read the article

  • Parse an XML file

    - by karan@dotnet
    The following code shows a simple method of parsing through an XML file/string. We can get the parent name, child name, attributes etc from the XML. The namespace System.Xml would be the only additional namespace that we would be using. string myXMl = "<Employees>" + "<Employee ID='1' Name='John Mayer'" + "Address='12th Street'" + "City='New York' Zip='10004'>" + "</Employee>" + "</Employees>"; XmlDocument xDoc = new XmlDocument();xDoc.LoadXml(myXMl);XmlNodeList xNodeList = xDoc.SelectNodes("Employees/child::node()");foreach (XmlNode xNode in xNodeList){ if (xNode.Name == "Employee") { string ID = xNode.Attributes["ID"].Value; //Outputs: 1 string Name = xNode.Attributes["Name"].Value;//Outputs: John Mayer string Address = xNode.Attributes["Address"].Value;//Outputs: 12th Street string City = xNode.Attributes["City"].Value;//Outputs: New York string Zip = xNode.Attributes["Zip"].Value; //Outputs: 10004 }} Lets look at another XML: string myXMl = "<root>" + "<parent1>..some data</parent1>" + "<parent2>" + "<Child1 id='1' name='Adam'>data1</Child1>" + "<Child2 id='2' name='Stanley'>data2</Child2>" + "</parent2>" + "</root>"; XmlDocument xDoc = new XmlDocument();xDoc.LoadXml(myXMl);XmlNodeList xNodeList = xDoc.SelectNodes("root/child::node()"); //Traverse the entire XML nodes.foreach (XmlNode xNode in xNodeList) { //Looks for any particular nodes if (xNode.Name == "parent1") { //some traversing.... } if (xNode.Name == "parent2") { //If the parent node has child nodes then //traverse the child nodes foreach (XmlNode xNode1 in xNode.ChildNodes) { string childNodeName = xNode1.Name; //Ouputs: Child1 string childNodeData = xNode1.InnerText; //Outputs: data1 //Loop through each attribute of the child nodes foreach (XmlAttribute xAtt in xNode1.Attributes) { string attrName = xAtt.Name; //Outputs: id string attrValue = xAtt.Value; //Outputs: 1 } } }}  

    Read the article

  • Extending DOMDocument and DOMNode: problem with return object

    - by Glauber Rocha
    I'm trying to extend the DOMDocument class so as to make XPath selections easier. I wrote this piece of code: class myDOMDocument extends DOMDocument { function selectNodes($xpath){ $oxpath = new DOMXPath($this); return $oxpath->query($xpath); } function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } These methods return a DOMNodeList and a DOMNode object, respectively. What I'd like to do now is to implement similar methods to the DOMNode objects. But obviously if I write a class (myDOMNode) that extends DOMNode, I won't be able to use these two extra methods on the nodes returned by myDOMDocument because they're DOMNode (and not myDOMNode) objects. I'm rather a beginner in object programming, I've tried various ideas but they all lead to a dead-end. Any hints? Thanks a lot in advance.

    Read the article

  • Help in XPath expression

    - by Ashish Gupta
    I have an XML document which contains nodes like following:- <a class="custom">test</a> <a class="xyz"></a> I was tryng to get the nodes for which class is NOT "Custom" and I wrote an expression like following:- XmlNodeList nodeList = document.SelectNodes("//*[self::A[@class!='custom'] or self::a[@class!='custom']]"); Now, I want to get IMG tags as well and I want to add the following experession as well to the above expression:- //*[self::IMG or self::img] ...so that I get all the IMG nodes as well and any tag other than having "custom" as value in the class attribute. Any help will be appreciated. EDIT :- I tried the following and this is an invalid syntax as this returns a boolean and not any nodelist:- XmlNodeList nodeList = document.SelectNodes("//*[self::A[@class!='custom'] or self::a[@class!='custom']] && [self::IMG or self::img]");

    Read the article

  • How to parse app.config using ConfigurationManager?

    - by Amokrane
    I was using a certain method for parsing my app.config file. Then I was told that using ConfigurationManager is better and simpler. But the thing is I don't know how to do it with ConfigurationManager. My original code looked like this: XmlNode xmlProvidersNode; XmlNodeList xmlProvidersList; XmlNodeList xmlTaskFactoriesList; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("app.config"); xmlProvidersNode = xmlDoc.DocumentElement.SelectSingleNode("TaskProviders"); xmlProvidersList = xmlProvidersNode.SelectNodes("TaskProvider"); foreach (XmlNode xmlProviderElement in xmlProvidersList) { if (xmlProviderElement.Attributes.GetNamedItem("Name").Value.Equals(_taskProvider)) { xmlTaskFactoriesList = xmlProviderElement.SelectNodes("TaskTypeFactory"); foreach (XmlNode xmlTaskFactoryElement in xmlTaskFactoriesList) { if (xmlTaskFactoryElement.Attributes.GetNamedItem("TaskType").Value.Equals(_taskType)) { taskTypeFactory = xmlTaskFactoryElement.Attributes.GetNamedItem("Class").Value; } } } } What would be the equivalent using ConfigurationManager? (Because all I can see is how to get keys not nodes..) Thanks

    Read the article

  • Relative XPath selection using XmlNode (c#)

    - by maxp
    Say i have the following xml file: <a> <b> <c></c> </b> <b> <c></c> </b> </a> var nodes = doc.SelectNodes("/a/b"); will select the two b nodes. I then loop these two nodes suchas: foreach (XmlNode node in nodes) { } However, when i call node.SelectNodes("/a/b/c"); It still returns both values and not just the descendants. Is it possible to select nodes only descening from the current node?

    Read the article

  • VBScript Can not Select XML nodes

    - by urbanMethod
    I am trying to Select nodes from some webservice response XML to no avail. For some reason I am able to select the root node ("xmldata") however, when I try to drill deeper("xmldata/customers") everything is returned empty! Below is the a sample of the XML that is returned by the webservice. <xmldata> <customers> <customerid>22506</customerid> <firstname>Jim</firstname> <issuperadmin>N</issuperadmin> <lastname>Jones</lastname> </customers> </xmldata> and here is the code I am trying to select customerid, firstname, and lastname; ' Send the Xml oXMLHttp.send Xml_to_Send ' Validate the Xml dim xmlDoc set xmlDoc = Server.CreateObject("Msxml2.DOMDocument") xmlDoc.load (oXMLHttp.ResponseXML.text) if(len(xmlDoc.text) = 0) then Xml_Returned = "<B>ERROR in Response xml:<BR>ERROR DETAILS:</B><BR><HR><BR>" end if dim nodeList Set nodeList = xmlDoc.SelectNodes("xmldata/customers") For Each itemAttrib In nodeList dim custID, custLname, custFname custID =itemAttrib.selectSingleNode("customerid").text custLname =itemAttrib.selectSingleNode("lastname").text custFname =itemAttrib.selectSingleNode("firstname").text response.write("News Subject: " & custID) response.write("<br />News Subject: " & custLname) response.write("<br />News Date: " & custFname) Next The result of the code above is zilch! nothing is written to the page. One strange thing is if I select the root element and get its length as follows; Set nodeList = xmlDoc.SelectNodes("xmldata") Response.Write(nodeList.length) '1 is written to page It correctly determines the length of 1. However when I try the same with the next node down as follows; Set nodeList2 = xmlDoc.SelectNodes("xmldata/customers") Response.Write(nodeList.length) '0 is written to page It returns a length of 0. WHY! Please note that this isn't the only way I have attempted to access the values of these nodes. I just can not work out what I am doing wrong. Could someone please help me out. Cheers.

    Read the article

  • setTimeout in javascript not giving browser 'breathing room'

    - by C Bauer
    Alright, I thought I had this whole setTimeout thing perfect but I seem to be horribly mistaken. I'm using excanvas and javascript to draw a map of my home state, however the drawing procedure chokes the browser. Right now I'm forced to pander to IE6 because I'm in a big organisation, which is probably a large part of the slowness. So what I thought I'd do is build a procedure called distributedDrawPolys (I'm probably using the wrong word there, so don't focus on the word distributed) which basically pops the polygons off of a global array in order to draw 50 of them at a time. This is the method that pushes the polygons on to the global array and runs the setTimeout: for (var x = 0; x < polygon.length; x++) { coordsObject.push(polygon[x]); fifty++; if (fifty > 49) { timeOutID = setTimeout(distributedDrawPolys, 5000); fifty = 0; } } I put an alert at the end of that method, it runs in practically a second. The distributed method looks like: function distributedDrawPolys() { if (coordsObject.length > 0) { for (x = 0; x < 50; x++) { //Only do 50 polygons var polygon = coordsObject.pop(); var coordinate = polygon.selectNodes("Coordinates/point"); var zip = polygon.selectNodes("ZipCode"); var rating = polygon.selectNodes("Score"); if (zip[0].text.indexOf("HH") == -1) { var lastOriginCoord = []; for (var y = 0; y < coordinate.length; y++) { var point = coordinate[y]; latitude = shiftLat(point.getAttribute("lat")); longitude = shiftLong(point.getAttribute("long")); if (y == 0) { lastOriginCoord[0] = point.getAttribute("long"); lastOriginCoord[1] = point.getAttribute("lat"); } if (y == 1) { beginPoly(longitude, latitude); } if (y > 0) { if (translateLongToX(longitude) > 0 && translateLongToX(longitude) < 800 && translateLatToY(latitude) > 0 && translateLatToY(latitude) < 600) { drawPolyPoint(longitude, latitude); } } } y = 0; if (zip[0].text != targetZipCode) { if (rating[0] != null) { if (rating[0].text == "Excellent") { endPoly("rgb(0,153,0)"); } else if (rating[0].text == "Good") { endPoly("rgb(153,204,102)"); } else if (rating[0].text == "Average") { endPoly("rgb(255,255,153)"); } } else { endPoly("rgb(255,255,255)"); } } else { endPoly("rgb(255,0,0)"); } } } } Ugh I don't know if that is properly formatted, I ended up with an extra bracket < So I thought the setTimeout method would allow the site to draw the polygons in groups so the users would be able to interact with the page while it was still drawing. What am I doing wrong here?

    Read the article

  • How do I select the shallowest matching elements with XPath?

    - by harpo
    Let's say I have this document. <a:Root> <a:A> <title><a:B/></title> <a:C> <item><a:D/></item> </a:C> </a:A> </a:Root> And I have an XmlNode set to the <a:A> element. If I say A.SelectNodes( "//a:*", namespaceManager ) I get B, C, and D. But I don't want D because it's nested in another "a:" element. If I say A.SelectNodes( "//a:*[not(ancestor::a:*)]", namespaceManager ) of course, I get nothing, since both A and its parent are in the "a" namespace. How can I select just B and C, that is, the shallowest children matching the namespace? Thanks. Note, this is XPath 1.0 (.NET 2), so I can't use in-scope-prefixes (which it appears would help).

    Read the article

1 2 3 4  | Next Page >