?
Solved

XPath XML EXTRACTION

Posted on 2013-01-25
10
Medium Priority
?
289 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

752 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