[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: merging multiple XML documents

  • From: Rick JELLIFFE <ricko@g...>
  • To: "Kaszubski, William J." <bill.kaszubski@C...>
  • Date: Tue, 16 May 2000 04:19:27 +0800

perl merge xml documents
"Kaszubski, William J." wrote:
> 
> We have a situation where we need to merge several (anywhere from 2 to 100)
> XML documents into one document that is the union of all the documents. All
> the documents are valid (to the same DTD) and well-formed, and each of the
> lowest-level nodes can be uniquely identified by its value and the values of
> all of its ancestors. All of the nodes in the subdocuments all are sorted so
> that they appear in ascending order according to this unique identifier. We
> need to end up with a document that has the same structure as the input
> documents, contains all of the unique nodes from all the input documents,
> and is also sorted according to the unique identifier.
> 
> Obviously , we can parse each one with the DOM, walk through them all
> simultaneously looking for the node that should appear next, and then copy
> one node at a time to yet another DOM instance, but we fear this might be a
> little slow <g>. Any ideas? Could SAX help here? Is this an XSL problem?
> Where should we begin?

You might find you can do this using entities.

 1) Make each element that needs to be sorted into a separate entity 
(either internal or external) declaration.  Use the sort key as the
entity name
(you may have to play with it if the sort key isnt a NMTOKEN).  (You may
find
 OmniMark or Perl good for this.)

 2) Then create a document/file/stream containing references to all
these entities. 
 (You may find OmniMark or Perl or sgrep good for this.)

 3) Sort that (e.g. using GNU sort or perl or anything) 

 4) Include it into a hub document. 

That way you do everything you need on a streaming basis, with no need
to build any
trees or do any DOM work.  You end up with a document like this

<!DOCTYPE xxx SYSTEM "my.dtd"
[
 <!ENTITY aaaaa1 "<yy><mykey>aaaaa1</mykey><mydata>blah</mydata></yy>" >
 <!ENTITY aaaaa2 "<yy><mydata>blah</mydata><mykey>aaaaa2</mykey></yy>" >
 <!ENTITY aaaab8 "<yy><mykey>aaaab8</mykey><mydata>blah</mydata></yy>" >
]
<xxx>
&aaaaa1;
&aaaaa2;
&aaaab8;
</xxx>

If you normalize this (reserialize it) you will get a more
conventional-looking
XML document (since an XML processor does not have to preserve entity
structure, which is just as well).  

This technique is very common in stream-based SGML systems and can be
very
effective.

Rick Jelliffe

***************************************************************************
This is xml-dev, the mailing list for XML developers.
To unsubscribe, mailto:majordomo@x...&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/
***************************************************************************

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.