Jump to content

Jaxp Xml Processing


awitt

Recommended Posts

I need to do some simple XML processing using Java. All I have to do is step through an XML file until I find a match to a file name that is stored within each element. I use Java often, but I'm unfamiliar with the JAXP APIs. Can anyone get me started?

Link to comment
Share on other sites

I have done quite a bit in asp working xml with JScript and VBscript.I was torn for a while about xml was told uses up to much memory, and php would be better than asp.The past week I found many articles which did say xml parses eat up to much back in 1999-2002 with facts, not so n so siad in a blog or message reply.I did find many other article to repute that stating that many finacail xml databases and software have purchased xml databases to keep and compile reocds and data.How, the upgrade to servers needed to be upgraded to at least a 1gig to 1.5gig costing $1,500.00 (in 2005)Ever since then I have never found any more bench testing to display actual findings in the past 4 years or more.Most of that xml is not better statements made, may be from the older pasrses and server performance of the older pre bench tast.1) in the beginning many parses would hold the the data upin memory without releaseing it, since then extra scripts have been written to clear the memory or release it after it is done. I even read that server upgrades have even put those on the server side applications to prevent memory hogging. ** so from learning that made me to believe that is way XML never died off, AND has grown into full software packages you can buy to run business record databases.I would have to agree that as new applications and software comes out, such like games and processors from pentium to core duo to xp, or windows 98 to vista. AS new ways to do things happen, computers and servers need to be up graded as well. Even same goes for graphics cards to support new programs.last I compared that even more stuff leans toward xml and mysql like asp.net and even complete xml database software running business records.I tried finding out "which parses are better then others" but the web did not reveal that information. so which xml many new softwares are using is unknown to me, but did find both PHP, asp, asp.net plateforms, but MOST useing asp.net.I could show you some simple code on either JSrcipt or VBscript, But I use both and use both languges on the same page.

Link to comment
Share on other sites

While I honestly do appreciate all the info about why or why not XML may be good, I need some help using a Java based approach, specifically outputting a certain attribute within an XML element onto a JSP page. So, really, all I need is some direction or tips using a JAXP API. I've actually done some XML parsing and processing using JavaScript before, but, unfortunately for me, I cannot use that approach this time. Thank you, though, stransky.

Link to comment
Share on other sites

I've actually done some XML parsing and processing using JavaScript before, but, unfortunately for me, I cannot use that approach this time. Thank you, though, stransky.
Actually, you can. Java has a DOM API. If memory becomes a concern, there's even an XMLStreamReader API.
Link to comment
Share on other sites

While I honestly do appreciate all the info about why or why not XML may be good, I need some help using a Java based approach, specifically outputting a certain attribute within an XML element onto a JSP page. So, really, all I need is some direction or tips using a JAXP API. I've actually done some XML parsing and processing using JavaScript before, but, unfortunately for me, I cannot use that approach this time. Thank you, though, stransky.
Sorry my bad, "JSP"http://www.devsphere.com/xml/taglib/output/examples.htmlhttp://java.sun.com/developer/codesamples/xml.html"outputting a certain attribute within an XML element onto a JSP page"are you trying to show/loop thought for each element, or are you trying to find/filter/match for a certin xml element?I messed with some jsp/jaxp a while back but could not get any where (like 3 years ago). But I don't mind helping out is you could give a heads up as to "outputting a certain attribute" in what manner.
Link to comment
Share on other sites

Hmm, interesting responses. Firstly, to boen_robot: so you're saying I can use the same methods and such to manipulate the XML DOM, the same way I did with JavaScript? That's what I'd rather do; I know it more and this is a static, hosted XML file, so it's not going to be growing or anything like that. Secondly, to stransky: here's the purpose for my endeavors. I have a static XML file that contains, among other things, an originalFileKey and an AssetID. What's happening is that a user will be visiting a URL with a filename (i.e. the originalFileKey) and I will pull that filename from the URL and then perform a search against the XML file. The search's goal is to match the URL-given filename with the originalFileKey in the XML. Then, once I find an element in the XML file that contains a match, I go through that particular element and grab the corresponding assetID. Once I have the assetID, all I need to do, for now, is output it to the JSP with which I'm working.

Link to comment
Share on other sites

It's worth noting that unlike JavaScript, JAVA also has a consistent XPath API - here's an example, and here's the actual documentation. If you can use XPath, you'll probably save yourself some lines of codes... or maybe not. In PHP you do, but from the sample in that first article, it seems that may not always be the case for JAVA.

Link to comment
Share on other sites

Hmm, interesting responses. Firstly, to boen_robot: so you're saying I can use the same methods and such to manipulate the XML DOM, the same way I did with JavaScript? That's what I'd rather do; I know it more and this is a static, hosted XML file, so it's not going to be growing or anything like that. Secondly, to stransky: here's the purpose for my endeavors. I have a static XML file that contains, among other things, an originalFileKey and an AssetID. What's happening is that a user will be visiting a URL with a filename (i.e. the originalFileKey) and I will pull that filename from the URL and then perform a search against the XML file. The search's goal is to match the URL-given filename with the originalFileKey in the XML. Then, once I find an element in the XML file that contains a match, I go through that particular element and grab the corresponding assetID. Once I have the assetID, all I need to do, for now, is output it to the JSP with which I'm working.
OK let me get this right in my own words. say a visitor click your fruits list page by the url link key1) the visitor may be on a page ?apples url?q=originalFileKey-friut and say you have a bunch of listings 1-20 apples url?q=assetID#1pears url?q=assetID#2grapes url?q=assetID#3bannanas url?q=assetID#4now if the visitor clicks grapes url?q=assetID#3you want to reload the xml to display just the matching only/all "assetID#3"then the visitor would be looking at your grapes xml write up.(bottom line) if so, your are passing a query from a link to be display as a url,then by the url you are passing that query to filter the xml to display the matched output.
Link to comment
Share on other sites

I think you're on the right trail. Let me see if I can create a visual:The user wants to watch one of our hosted videos, but that video is hosted somewhere else now. The old link references that video (that used to be on our file system) using the file name, which in the XML file I have, is called originalFileKey. But now, it's in another system, which references the file by a system-generated assetID. The XML file I have is from this new system, so it does contain both the old 'file name' (originalFileKey) and the new 'file name' (assetID). So my purpose is to find out what the new system calls this old file by searching through the XML file and linking up the originalFileKey with the assetID. Eventually, this will turn into an Apache redirect, but for now, I just want to output the assetID onto the page - that's all that is necessary for right now.

Link to comment
Share on other sites

I think you're on the right trail. Let me see if I can create a visual:The user wants to watch one of our hosted videos, but that video is hosted somewhere else now. The old link references that video (that used to be on our file system) using the file name, which in the XML file I have, is called originalFileKey. But now, it's in another system, which references the file by a system-generated assetID. The XML file I have is from this new system, so it does contain both the old 'file name' (originalFileKey) and the new 'file name' (assetID). So my purpose is to find out what the new system calls this old file by searching through the XML file and linking up the originalFileKey with the assetID. Eventually, this will turn into an Apache redirect, but for now, I just want to output the assetID onto the page - that's all that is necessary for right now.
with an xml file are you able to create an extra node? if so you could have say <xmldata> <movie> <originalkey>234</originalkey> <originaltitle>###### boy</originaltitle> <originaldesc>great movie</originaldesc> <other tags....../> <newassetstatus>785</newassetstatus> <newassetsite>www.newsite.location</newassetsite> <newassetkey>/files/movies.asp</newassetkey><movie></xmldata>You could say set a global variable like www.newsitelocation.com then add in the redirect file path to its urlLike if you display the title of a movie and its description, then the link could be either one or jion two node tags to be a link to the new locationhttp site + the location keyor one tag httpp and the location filethis way from your site if the link is click it will take them to the updated location--------in an xslt if you are useing one, you can filter for ###### Boythen as it display use a when test commandif newassetstatus <> ""/>you will then use xslt to create the new link (Not sure if you use asp or php with xslt)but then join your new nodes in a href output."http://" + newassetsite + "" + newassetkey + "?" + newassetstatus + ""I am not looking at an actual xslt output, but if you have done codes like that befor you can get my jest, I do that type of output from xmldom and asp all the time with banner displays and link pages by key word filtering.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...