[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

XPath XML EXTRACTION

Posted on 2013-01-25
10
Medium Priority
?
290 Views
Last Modified: 2013-11-19
hOW DO i JUST EXTRACT Firstname Lastname and Position from this file. I need it in java or javascript or some sort of web output html. attached is the xml file. It is a Baseball Batting lineup. Please Help !
38511.XML
0
Comment
Question by:powerztom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 11

Accepted Solution

by:
mcnute earned 1200 total points
ID: 38822311
you can do it with jquery like so:

<!DOCTYPE HTML>
  <html>
  <head>    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
   $(document).ready(function()
{
  $.ajax({
    type: "GET",
    url: "xml-parsing.xml",  // put here instead, whatever you xml file is called.
    dataType: "xml",
    success: parseXml
  });
});
    
    
    function parseXml(xml)
{
  //find every Tutorial and print the author
  $(xml).find("Player").each(function() {
      var fname = $(this).attr("FirstName");
      var lname = $(this).attr("Lastname");
      console.log("State: " + fname + " Code: " + lname);
    });

  // Output:
  // The Reddest
  // The Hairiest
  // The Tallest
  // The Fattest
}
    
    
    
    
    </script>
  </head>
  <body>
  </body>
</html>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38822312
What scripting languages do you have at hand?  Do you have PHP?
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38822314
My script above is tested on my local server and worked like a charme. It has been done with javascript. Enjoy!
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 46

Expert Comment

by:aikimark
ID: 38822938
You could also do this with XSLT.
0
 

Author Comment

by:powerztom
ID: 38852535
I cannot get it what about this link http://www.sportsnetwork.com/xml/mlb/scores/real/33301.xml. I have to pull stats from players as well as Player Info and Scoring for the innings I tried that script but it do not execute how do you call it and have it write to a html table just as an example.
0
 

Author Comment

by:powerztom
ID: 38852602
Need Help!!!
0
 

Author Comment

by:powerztom
ID: 38855044
I tried jquery script however I had no luck
<!DOCTYPE HTML>
  <html>
  <head>    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
   $(document).ready(function()
{
  $.ajax({
    type: "GET",
    url: "http://www.sportsnetwork.com/xml/mlb/scores/real/33011.xml",  // put here instead, whatever you xml file is called.
    dataType: "xml",
    success: parseXml
  });
});
   
   
    function parseXml(xml)
{
  //find every Tutorial and print the author
  $(xml).find("Player").each(function() {
      var fname = $(this).attr("FirstName");
      var lname = $(this).attr("Lastname");
      console.log("State: " + fname + " Code: " + lname);
    });

  // Output:
  // The Reddest
  // The Hairiest
  // The Tallest
  // The Fattest
}
   
   
   
   
    </script>
  </head>
  <body>
  </body>
</html>

How do you call the function ?
0
 

Author Comment

by:powerztom
ID: 38856039
Script work in IE not Firefox or Chrome How can I get the script to run in all 3 browsers and how do I loop the function I'm not that go at for loops I just need the loop to cycle trough the lineup. Please Help!
0
 

Author Closing Comment

by:powerztom
ID: 38856970
This is almost Right however it only works in IE not Firefox and Crome.
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question