Solved

XPath XML EXTRACTION

Posted on 2013-01-25
10
283 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 108

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
 
LVL 45

Expert Comment

by:aikimark
ID: 38822938
You could also do this with XSLT.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now