How can I convert an XML Object into a Javascript Object? - javascript

I have a project I need to do that requires the use of xml and javascript, however I'm not experienced in either.
Basicly its for a company that posts jobs in an rss feed using xml, and what they need is to have a page that allows a user to type in a search query, click a search button and have a list of available jobs returned back to them with only the title and the link, and upon clicking the link they will be directed to the full rss xml item. which they can then read.
Now as far as my logic goes, I don't know how to use jquery and quite honestly I don't think its necesary, I think that all this project needs is a bit of ajax however firstly one would need to create an xml object, convert it to a javascript object and only then manipulate it. etc...
If anyone has any insight I'd really appreciate it.

Related

I need to get an Instagram User ID# for use in Google Script

I'd like to take a username and plug it into this format
https://www.instagram.com/{username}/?__a=1
thanks to this thread for that tip
I then need to follow that link in java, and when doing so it presents the following page code, which I've abridged to save space. I used professional Skateboarder Nyjah Huston as my example.
{"logging_page_id":"profilePage_8223552","show_suggested_profiles":false,"show_follow_dialog":false,"graphql":{"user":{"biography":"Sender\ud83d\ude08\n#nikesb #monsterenergy #elementbrand #blackplaguebrewing #socialcbd #priverevaux","blocked_by_viewer":false,"restricted_by_viewer":null,"country_block":false,"external_url":"https://www.nike.com/t/sb-nyjah-free-skate-shoe-oKwn7N/AA4272-300","external_url_linkshimmed":"https://l.instagram.com/?u=https%3A%2F%2Fwww.nike.com%2Ft%2Fsb-nyjah-free-skate-shoe-oKwn7N%2FAA4272-300&e=ATMW9Q8NwN2Mcwm_Bd5I8DeuAKP4L7IHpy_PdylDnGU8qqokJU6Z1kh_emEIVfJ1q8Xtq1b0&s=1","edge_followed_by":{"count":3969537},"followed_by_viewer":false,"edge_follow":{"count":694},"follows_viewer":false,"full_name":"Nyjah Huston"
As you can see, the User ID is one of the first things on the page
{"logging_page_id":"profilePage_8223552"
the user id being 8223552 in this case. I'm quite new to java, and I need to know how to follow that link and parse that data in order to turn the user id into a var for use in my google script. Thank you for your help!
You can easily parse this JSON content to a object that has only the information you need:
class UserInformation{
private String logging_page_id;
}
I suggest this option because if you need in the future to get another info, you can easily just extend the object.
How to do the conversion, please reference to this stackoverflow

How do I fetch a web response to use as a variable in HTML/JavaScript

So I have a tag in my HTML where onclick calls a JavaScript script, and passes a number to it:
<svg id="fillgauge1" onclick="gauge1.update(42);"></svg>
But I also have a web service that streams a number back to me (as text/plain):
http://myserver/stream?GetNumber&token=xyz
What I want is to be able to do is take the result of that service, and pass it to the JavaScript, sort of like this:
<svg id="fillgauge1" onclick="gauge1.update(http://myserver/stream?GetNumber&token=xyz);"></svg>
But, obviously, it isn't as simple as that!
I guess I'm asking a couple of things. Is there a way to retrieve the value like this, within the HTML, or should the operation go into the JavaScript? And if it should go into the JavaScript, what technique or commands do I use? I'm fairly inexperienced (which I'm sure shows) but I can research what to do if I can just get some pointers. My Googling just isn't finding what approach to take, so I'm kind of lost, and any suggestions would be appreciated.
To clarify the scenario, I have an SVG object with a number label on it. The user clicking the object causes the number to update. I can make it update to a fixed value, but I'd like to get that number, live, from a web service. I can easily change that service from serving text/plain to XML or JSON if that's a better technique.

Run Database Stored RegEx against DOM

I have a question about how to approach a certain scenario before I get halfway through it and figure out it was not the best option.
I work for a large company that has a team that creates tools for the team mates to use that aren’t official enterprise tools. We have no access to the database directly, just access to an internal server to store our files to run and be able to access the main site with javascript etc (same domain).
What I am working on is a tool that has a ton of options in it that allow you to select that I will call “data points” on a page.
There are things like “Account status, Balance, Name, Phone number, email etc” and have it save those to an excel sheet.
So you input account numbers, choose what you need and then using IE Objects it navigates to the page and scrapes data you request.
My question is as follows..
I want to make the scraping part pretty Dynamic in the way it works. I want to be able to add new datapoints on the fly.
My goal or idea is so store the regular expression needed to get the specific piece of data in the table with the “data point option”.
If I choose “Name” it knows the expression for name in the database to run again the DOM.
What would be the best way about creating that type of function in Javascript / Jquery?
I need to pass a Regex to a function, have it run against the DOM and then return the result.
I have a feeling that there will be things that require more than 1 step to get the information etc.
I am just trying to think of the best way to approach it without having to hardcode 200+ expressions into the file as the page may get updated and need to be changed.
Any ideas?
IRobotSoft scraper may be the tool you are looking for. Check this forum and see if questions are similar to what you are doing: http://irobotsoft.org/bb/YaBB.pl?board=newcomer. It is free.
What it uses is not regular expression but a language called HTQL, which may be more suitable for extracting web pages. It also supports regular expression, but not as the main language.
It organizes all your actions well with a visual interface, so you can dynamically compose actions or tasks for changing needs.

Javascript Widgets

I am wanting to make a Javascript widget that can pull "X" number of the most recent posts from a RSS Feed.
My question is:
What is the fundamentals that i should be looking into in order to achieve this?
AJAX or JSON/script-tag methods of retrieving remote data from the browser (or writing a server-side proxy to retrieve data and set it up for your widget to consume from the browser)
DOM manipulation, for formatting your data into markup on a page
CSS for styling your markup
Yahoo! Pipes can be very helpful for this sort of thing... this Pipe can take your X and your RSS feed URL and return JSON for you to work with in JavaScript, saving tons of time... http://pipes.yahoo.com/pipes/pipe.info?_id=2FV68p9G3BGVbc7IdLq02Q

XML File Parse in javascript how to. Large File maybe use SAX?

G'day All,
I am pulling my hair out, getting headaches and my eyes hurt. I have been hither and thither and I seem to get whither.
This will be my first experience with xml and would really want to get this working. It is a large file. Well large in my eyes +-5mb. I can not imagine that this file would be loaded into memory to process. Users will get a bit peeved with this.
Basically we are using a 3rd parties site to do our ecommerce. So we have no access to the database other than via the admin area.
What we want to do is make sure that there is no stuff ups when it comes to addresses. Therefore we got this xml file put together listing all postcodes with areas and states:
<?xml version="1.0"?>
<POSTCODES>
<PostCode id="2035">
<Area>2035 1</Area>
<Area>2035 2</Area>
<Area>2035 3</Area>
<State>NSW</State>
</Postcode>
<PostCode id="2038">
<Area>2038 1</Area>
<Area>2038 2</Area>
<Area>2038 3</Area>
<State>NSW</State>
</Postcode>
<PostCode id="2111">
<Area>2111 1</Area>
<Area>2111 2</Area>
<Area>2111 3</Area>
<State>NSW</State>
</Postcode>
</POSTCODES>
Someone suggested SAX but suddenly died when asked how? The web is not helping unless I am not looking properly. I see a lot of examples. Either they do not show how to read the file but rather do it from a textarea or the example is in java.
What do we want? User enters a post code of 2038. We want to go to the javascript with that data and have returned to us all the suburbs that full within that post code.
Anyone out there that can please tell me what to download and how to use it to get what i need?
Please, please, please. It is hard to see a grown man begging and crying but I am.
Sounds like you want a script on the server which will suggest suburbs based on the users postcode selection? You could use jQuery's ajax functionality to do this.
You might also be able to use jQueryUI's autocomplete control to parse XML and make suggestions: http://jqueryui.com/demos/autocomplete/#xml
It's also possible to do this entirely in javascript without any script on the server side, but it would be pretty slow at loading if the XML file is 5MB. You might be able to get a significant reduction in file size thought by gzipping it before transmission from the server.
If you need to parse this in Javascript, you can use jQuery.
http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery

Categories

Resources