Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 6th, 2008, 05:41 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default XML differences

I'm working on finding differences in 2 xml files. I need to check for new text, new tags, new attributes, etc., whichever is new. I can find that there is a change. But I can't locate the exact line-number. Is there any way?
File1.xml
<?xml version="1.0" encoding="UTF-8"?>
<file1>
  <file11 href="ha">test1</file11>
  <file12 href="">test2</file12>
</file1>
File2.xml
<?xml version="1.0" encoding="UTF-8"?>
<file1>
  <file21>test2</file21>
  <file22 href="hai">test1</file22>
</file1>


__________________
Rummy
  #2 (permalink)  
Old October 6th, 2008, 06:08 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You don't say anything about the technology you are using.

Most of the standard tree models (DOM, JDOM, etc) don't give you any line number information.

It's available from SAX and StAX parsers, but that's a bit low-level.

If you're using Saxon, there's an option to maintain line numbers and retrieve them using the saxon:line-number() extension function.

Incidentally, there are products like DeltaXML that do this for you, and much better that you could hope to achieve in something home-grown.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old October 6th, 2008, 06:23 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Thanks Mike. I'm using XSLT 2.0 with Saxon processor.
I can't opt for products like DeltaXML. Is there any way to do it through code?

thanks in advance

  #4 (permalink)  
Old October 6th, 2008, 07:32 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In Saxon you can cause line numbers to be maintained using -l from the command line or the equivalent from the API (e.g TransformerFactory.setAttribute("http://saxon.sf.net/feature/linenumbering", Boolean.TRUE), and you can then access the line number using saxon:line-number(), as already mentioned.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
  #5 (permalink)  
Old October 6th, 2008, 07:34 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Thank Mike.



Similar Threads
Thread Thread Starter Forum Replies Last Post
mozilla/IE 7 differences Adam H-W CSS Cascading Style Sheets 2 July 9th, 2007 04:16 AM
Xcode 2.4 differences craigontour Xcode 1 November 24th, 2006 11:08 PM
Java code to find differences in XML like ExamXML alapick Java Basics 1 July 28th, 2006 04:15 AM
objDataAdapter Differences cpbittner BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 September 20th, 2004 08:09 PM
Variable Differences hugh@kmcnetwork.com ASP.NET 1.0 and 1.1 Basics 1 December 30th, 2003 12:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.