Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |

Fovo
Timetravel Enterprises
|
Posted - 2010.05.18 21:14:00 -
[1]
ok I am doing my best to figure this one out, but I am at my wits end. RegEx is a cool tool, but I have yet to Google an example I can use to parse out just the value from the api I am looking for.
If anyone can assist me, I would be grateful.
I am looking at the following url http://api.eve-central.com/api/marketstat?typeid=34®ionlimit=10000002
It is returning something similar to: <?xml version="1.0" encoding="UTF-8"?> <!-- Automatically generated data from EVE-Central.com --> <!-- This is the new API :-) --> <evec_api version="2.0" method="marketstat_xml"> <marketstat> <type id="34"> <all> <volume>69519715762.00</volume> <avg>2.79</avg> <max>50.95</max> <min>0.20</min> <stddev>1.92</stddev> <median>2.65</median> </all> <buy> <volume>35276199620.00</volume> <avg>2.45</avg> <max>2.80</max> <min>0.20</min> <stddev>0.53</stddev> <median>2.32</median> </buy> <sell> <volume>34243516142.00</volume> <avg>3.01</avg> <max>50.95</max> <min>2.48</min> <stddev>2.08</stddev> <median>2.74</median> </sell> </type> </marketstat> </evec_api>
my tool will load the page and parse out a single value. I can run this as many times as necessary passing in what ever regex criteria i like. teh issue is I cant seem to just get the numeric value I am after.
If anyone could give me an example of how to parse out the <sell> <AVG> value (in this example 3.01) I would really appreciate it.
Thanks Fovo
|

darius mclever
|
Posted - 2010.05.18 21:52:00 -
[2]
Edited by: darius mclever on 18/05/2010 21:54:57 instead of trying to use a regexp ever considered using an xml parser and xpath?
the xpath would be "//marketstat/sell/avg/text()"
|

Caelum Dominus
Genos Occidere
|
Posted - 2010.05.18 23:38:00 -
[3]
Darius is right; RegEx is not for parsing XML. You should be using an XML parser. If you tell us what programming language you're looking to write it in, we might be able to provide an example.
|

Xeross155
Minmatar Fusion Death Inc. Intrepid Crossing
|
Posted - 2010.05.19 05:44:00 -
[4]
If he needs just 1 specific value, and he needs to get it from a lot of xml strings regex might be faster. --------------------------------------------- Xeross' ventures into EVE |

darius mclever
|
Posted - 2010.05.19 08:42:00 -
[5]
Originally by: Xeross155 If he needs just 1 specific value, and he needs to get it from a lot of xml strings regex might be faster.
with all the cleaning up (removing whitespaces/newlines) of the xml to get some predictable format? I highly doubt that you are faster than using a native xml parser and putting the small xpath on it.
|

Catari Taga
Centre Of Attention Rough Necks
|
Posted - 2010.05.19 09:39:00 -
[6]
Originally by: darius mclever
Originally by: Xeross155 If he needs just 1 specific value, and he needs to get it from a lot of xml strings regex might be faster.
with all the cleaning up (removing whitespaces/newlines) of the xml to get some predictable format? I highly doubt that you are faster than using a native xml parser and putting the small xpath on it.
building the XML object would take more operations than the regex. Since he already knows the input format he could even speed it up and only process the line he's actually interested in.
--
Originally by: Zeke Mobius I swear the catholic church was faster at admitting the earth was round than CCP at fixing stuff.
|

Miss Direction
Laughing Leprechauns Corporation
|
Posted - 2010.05.19 10:19:00 -
[7]
Hi Fovo,
A regex that would select this value for you using a backreference would be
<avg\b[^>]*>(.*?)</avg>
It would carry over any whitespace however if it was present. Corp Main Site
|

Fovo
Timetravel Enterprises
|
Posted - 2010.05.19 20:35:00 -
[8]
Originally by: Miss Direction Hi Fovo,
A regex that would select this value for you using a backreference would be
<avg\b[^>]*>(.*?)</avg>
It would carry over any whitespace however if it was present.
I gave that a shot and it kept pulling the <avg> for <all> (Line 9) Returning the value 2.79.
It looks like you need some sort of embedded select.
Fovo
|

Tonto Auri
Vhero' Multipurpose Corp
|
Posted - 2010.05.19 21:40:00 -
[9]
What language you are using? It would be easier to provide complete solution rather than trying to pin the parts, especially when you are not very confident in your skills.
The general answer would be to match regexp against all entries rather than stop at first one. Then you would get all 3 results at once. Also, referring to the "any spaces" (although EVEc API is rather strict in this part), you can actually defer their appearance in the result using exact match.
<avg\b[^>]*>\s*(\d+(?:\.\d+))?\s*<\/avg>
However, I should warn you that in case of empty <avg/> tag your regexp will fail and you will get unreliable results. That's why it is generally advisable to use XML parsers for XML data. You could also request up to 25(?) type ids in single transaction, instead of hammering EVEc servers with multiple requests. -- Thanks CCP for cu |

Fovo
Timetravel Enterprises
|
Posted - 2010.05.19 22:47:00 -
[10]
Originally by: Tonto Auri What language you are using? It would be easier to provide complete solution rather than trying to pin the parts, especially when you are not very confident in your skills.
The general answer would be to match regexp against all entries rather than stop at first one. Then you would get all 3 results at once. Also, referring to the "any spaces" (although EVEc API is rather strict in this part), you can actually defer their appearance in the result using exact match.
<avg\b[^>]*>\s*(\d+(?:\.\d+))?\s*<\/avg>
However, I should warn you that in case of empty <avg/> tag your regexp will fail and you will get unreliable results. That's why it is generally advisable to use XML parsers for XML data. You could also request up to 25(?) type ids in single transaction, instead of hammering EVEc servers with multiple requests.
It is a web page that uses a java back end. The sum of it is I point it to the page, I tell it the url to go fetch and I provide it the regular expression to parse the page content with. The back end then saves the result (if there is one) to a database. Using a 3rd party parser or "Re-writing server code" isn't really an option. I either find a regular expression to give the server so it can do the work or I drop teh entire thing and call it a fail.
|
|

Fovo
Timetravel Enterprises
|
Posted - 2010.05.19 22:56:00 -
[11]
Originally by: Tonto Auri
<avg\b[^>]*>\s*(\d+(?:\.\d+))?\s*<\/avg>
This failed as well. I have been trying to use these example in RegEx Coach and both try and return all 3 avg valued 2.79 2.45 and 3.01.
I keep thinking it should look something like this <sell\b[^>]*>\s*(<avg\b[^>]*>\s*(\d+(?:\.\d+))?\s*<\/avg>)?\s*<\/sell>
Fovo
|

Fovo
Timetravel Enterprises
|
Posted - 2010.05.19 23:02:00 -
[12]
Perhaps I could have thought out the example a bit better.
Let me amend it slightly. lets focus on the avg buy price.
I would think either of the previous 2 examples would do if I could use the {n} expression. Then i could specify {2} for the buy average for example.
Fovo
|

darius mclever
|
Posted - 2010.05.20 04:04:00 -
[13]
in what language are you writing?
|

Lutz Major
Austriae Est Imperare Orbi Universo
|
Posted - 2010.05.20 08:41:00 -
[14]
Edited by: Lutz Major on 20/05/2010 08:47:09
Originally by: Fovo It is a web page that uses a java back end. The sum of it is I point it to the page, I tell it the url to go fetch and I provide it the regular expression to parse the page content with. The back end then saves the result (if there is one) to a database. Using a 3rd party parser or "Re-writing server code" isn't really an option. I either find a regular expression to give the server so it can do the work or I drop teh entire thing and call it a fail.
Do I get this right? You fetch and parse the file in Java? import java.net.URL; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.*; import org.w3c.dom.Document;
URL url = new URL("http://api.eve-central.com/api/marketstat?typeid=34®ionlimit=10000002"); Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream()); XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//marketstat/type/sell/avg/text()"); Object result = expr.evaluate(document);
If you want it even easier use an unmarshaller and annotations.
|

Fovo
Timetravel Enterprises
|
Posted - 2010.05.20 16:11:00 -
[15]
darius mclever The developer for the software package wrote it in Java. However I have no access the the source code, I just have to use the web interface that is provided. As stated earlier, I have to provide the URL and Regular Expression for the page content I want. Modifying the server side code is not an option.
Originally by: Lutz Major
Do I get this right? You fetch and parse the file in Java?
import java.net.URL; import javax.xml.xpath.*; import org.xml.sax.InputSource;
URL url = new URL("http://api.eve-central.com/api/marketstat?typeid=34®ionlimit=10000002"); XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//marketstat/type/sell/avg/text()"); String result = expr.evaluate(new InputSource(url.openStream()));
If you want it even easier use an unmarshaller and annotations. Edit: made it even simplier 
If I could rewrite the server code this might be an option, but this is a closed box appliance that I can only access via a web Interface.
Fovo
|

Lutz Major
Austriae Est Imperare Orbi Universo
|
Posted - 2010.05.20 16:56:00 -
[16]
Edited by: Lutz Major on 20/05/2010 17:00:07
.*<sell.*<avg>(\d*\.\d+)</.* Sooooo wrooooong! I go and wash my hands now!
Edit: BTW if the backend is Java, you will have to escape the '\' eventually, so the regex looks like this: .*<sell.*<avg>(\\d*\\.\\d+)</.*
|

Catari Taga
Centre Of Attention Rough Necks
|
Posted - 2010.05.20 18:07:00 -
[17]
Hey, can I add one to the party, too?
<sell[\s\S]+?<avg>(.+?)<
--
Originally by: Zeke Mobius I swear the catholic church was faster at admitting the earth was round than CCP at fixing stuff.
|

Fovo
Timetravel Enterprises
|
Posted - 2010.05.21 22:40:00 -
[18]
Looks like the last example may work. I will let you know as soon as I try it.
Fovo
|
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |