Solved

XPath XML EXTRACTION

Posted on 2013-01-25
10
284 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
10 Comments
 
LVL 11

Accepted Solution

by:
mcnute earned 400 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 109

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 45

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 72
Does video get better conversion rates? 2 45
Divi Them Help with Full Width header 20 59
Remove third quote mark from widget 6 23
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

808 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