How to display information contained in XML file from another website - javascript

I have an XML file ( XML file I produce ) which contains information about my parteners.
I want them to display on their website information relative to them by picking them into the XML file.
I have no idea to do that, ecxept that i need to write a 'parser' in javascript to display information. This javascript code i guess has to be on my partener's website.
could you please provide me examples to do that ? (how to write a parser, how to display only information for one partener ?)
Thank you,
Regards

I think this is a standard problem. Each browser does expose there own version of a Document type object which you can build and then use method like getElementByTagName to grab a particular node in the XML and process its data.
Few links which you can look at
http://www.hiteshagrawal.com/javascript/javascript-parsing-xml-in-javascript
http://www.mikechambers.com/blog/2006/01/09/parsing-xml-in-javascript/
I would suggest you to use prototype library for dealing with this

Related

How to convert Netscape-Bookmark-File-Format into well formed XML to manipulate

I have exported Netscape-Bookmark-Files as .html from Chrome, IE, and Firefox. These files are similar. Is there a way to convert this .html file into well-formed XML, for example, to view it in a TreeView in WPF? Or is there a workaround for that?
Maybe there is a better way to exchange Bookmarks under the Browsers which I don't know. Something like the JSON Files maybe....
I have to do a Project(C#) in which I have to program a little Bookmark Manager which I can Import and Export this HTML files as well as my own Bookmarks which are saved in a Database.... Do you have a better idea for this?
Please help me....
Regards
But i dont have JSON Files. I only have this f...ed up Netscape Bookmark File Format to work with. There is no Documentation for this Format. Only a poor one on Microsoft....
Treat each HTML <DT> tag like a new line.
In whatever language you have access to wrap each new line into a format that jstree.js can read so you end up with format as described here,
or simply use:
[{ id:lineCount, text:linedata},{rince and repeat}]
Then in whatever page you are using to display your tree load the json and you are good to go. Be careful you do not publish it openly as this writer would be concerned about any embeded authorization codes.
Another level of tricky would be to make each heading a parent. So in your preprocess you would create children object according to the above spec. As simple directory like re-entrant method (like you were going through a directory tree) would be able to child each group.
Then you would have
[{ id:lineCount, text:linedataParent, children[{id:lineCount, text:child, rince and repeat}, id:lineCount, text:nextParent, children:[{..and so on..}]...}]
Resulting in a somewhat nicer jsTree with parent/children the way you intended when you did your bookmark management.
Pretty sure this wont get voted best answer but it might be a start for you.

Docxtemplater inserting plain xml

I am using DocxTemplater library by edi9999 as a solution for creating .docx reports from template and JSON data, and I am happy with this.
However, now I have to highlight some words in my reports. For example, I need to substitute {contents} with some large text, where few words are highlighted.
It means that I have 2 solutions here:
Use some kind of markers inside of my data (like in this data one {highlight(red)}{word} is red, which are then interpreted by DocxTemplater.
Directly substitute tag with desired xml. For example, I substitute {contents} with this xml (stored in my JSON data as "contents" field): <w:r> <w:rPr> <w:highlight w:val="cyan"/>
</w:rPr> <w:t>lol</w:t> </w:r>. If I do this now, I get my XML embedded in <w:r><w:t>HERE</w:t></w:r>, so that MS Word thinks that file is corrupt.
For "raw" xml data I want to use some kind of special tag like {#myXmlData}, which will prevent library from surrounding contents with <w:r><w:t></w:t></w:r>.
I think that second solution is many ways superior and it is very flexible: it allows users to use DocxTemplater even if it doesn't satisfy some of their needs. They can just use XML for their very specific needs.
I think it is really great new feature for DocxTemplater library.
However, now I just want to solve my problem and I don't have time to thoroughly study or modify library's code.
It would be great if someone will point to places in library's code and ideas of how to easily extend it to add this feature.
EDIT: now this feature is supported! Check out https://github.com/edi9999/docxtemplater/issues/7
I have implemented this indeed after https://github.com/edi9999/docxtemplater/issues/7
You can write
In your docx:
{#rawXml}
In your data:
{
rawXml:'<w:p> <w:r> <w:rPr> <w:highlight w:val="cyan"/></w:rPr> <w:t>lol</w:t> </w:r> </w:p>'
}

Using a webpage/web application to read and collect elements from XSL file

I have xsl page which include a number of templates cover all i need to create the webpages i want, i call the templates using nodes into another xsl file,
I need to call and collect the templates into a webpage instead of xsl using dropdown-lists.
How can i achieve that?
It seems not easy so any thoughts could help!
Thanks in advance!
I find it pretty tricky too and don't have a full answer for you.
Display the templates should be the easy part. You could catch them via XQuery, javascript as xml element from an xml file (the XSL stylesheet).
To call just some specific templates, I don't know...
One way to achieve your goal, is maybe using webServices to call xslTransform. You could do that easily with eXist for example (http://en.wikibooks.org/wiki/XQuery/XQuery_and_XSLT#Creating_an_XSLT_service). Exist embedded Webservices provide such functions (ie. calling XSLT inside web context). You have similar functionnalies in javascript (I guess...).
Maybe using XQuery (or anything else) to dynamically generate a simple template stylesheet (ie : extracting the template and create a XSLT file with only it inside) and execute it could be a solution.
Another way, may be using the mode attributes of templates. You could set an execution mode for a XSLT when launching it. But you may find yourself with one specific mode for each template...
Hope this could help.

read information off website and store in excel file

I am trying to build this application that when provided a .txt file filled with isbn numbers will visit the isbn.nu page for that isbn number by simply appending the isbn to the url www.isbn.nu/your isbn number.
After pulling up the page, I want to scan it for information about the book, and store that in an excel file.
I was thinking about creating a file stream of the url in Java, but I am not really sure how to extract the information from the html page. Storing the information will be done using the JExcel Java package.
My best guess would be using javascript to extract the information, but I don't know how to call the javascript from my java program.
Is my idea plausible? if not, what do you guys suggest I do.
my goal: retrieve information from an html page and store it in an excel file for each ISBN in a text file. There can be any number of isbn's in a text file.
This isn't homework btw, I am simply doing this for an organization that donates books to Sudan. Currently they have 5 people cataloging these books manually and I am one of them.
Jsoup is a useful tool for parsing a web page and getting data from it. You can do it in Java and it's pretty easy.
You can parse the text file, build the URL with a string, send it in with JSoup then use JSoup to parse out the information using the html tags on the page. Then you can store it out however you want. You really don't need to use Javascript at all if you're more comfortable with Java.
Example for reading a page and parsing it with Jsoup:
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");
Use a div in which you load your link (example here how to do that http://api.jquery.com/load/).
After that when load is complete you can check what is the name of the div's or spans used in the webpage and get that content with val (http://api.jquery.com/val/) or text (http://api.jquery.com/text/)
Here is text from the main page of www.isbn.nu:
Please note that isbn.nu is designed for manual searching by individuals. It is not intended as an information resource for automated retrieval, nor as a research tool for companies. isbn.nu reserves the right to deny access based on excessive requests.
Why not just use the free Google books API that would return book details in XML format. There are many classes available in Java to parse XML feeds and would make your life much easier.
See http://code.google.com/apis/books/ for more info.
Here are the steps needed:
Create CURL request (you can use multiple curl requests)
Get body data
Parse data
Make excel file
You can read HTML information using this guide.
A simple solution might be to use a Google Docs spreadsheet function like ImportXML(URL,path-expression).
More information and examples here:
http://www.seerinteractive.com/blog/importxml-cookbook/
http://www.distilled.net/blog/distilled/guide-to-google-docs-importxml/
http://blog.ouseful.info/2008/10/14/data-scraping-wikipedia-with-google-spreadsheets/

Learn how to make Flair for my users (javascript snippets)

I wanted to give my users a little piece of JavaScript or HTML code that they could put on their site and show information about them. Kind of like StackOverFlows new feature Flair.
I have an idea of how to code it. I was going to give them some JS with a HTML that had a DIV id="MySite_Info". Then the JS would go to my site and pull some JSON or XML and then fill in the data with a DIV in the HTML I gave them on their site.
Is there a better way to do this? Or any examples online I should follow? Whats the best way to create these javascript snippets? (Not sure what the proper name is)
There are two basic options.
Images (and pictures of text suck)
JavaScript - as you described
The approach I would take would be to:
Dynamically generate the JS using a server side process. This would include data for the user (using a JSON generator to easily produce the data in a suitable format).
Build the badge using standard DOM methods
Find the element with the document id and appendChild the generated badge

Categories