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
Solved

XPath XML EXTRACTION

Posted on 2013-01-25
10
285 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Read about why website design really matters in today's demanding market.
This video teaches users how to migrate an existing Wordpress website to a new domain.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

860 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