• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSLT losing element and attribute names

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Initially I tried doing a transform (Transformer.transform()) passing in a StreamSource. This did not work for me (nothing to do with the above) because my real XML has a DTD reference and the transform process fails when it tries to load the DTD. So, I switched to a SAXSource which allowed me to get a handle to a SAXParser and XMLReader and resolve my entities. USING A SAXSource GENERATED THE XML ABOVE AND LOST ALL OF MY ELEMENT AND ATTRIBUTE NAMES. I tried using a DOMSource. This worked generating valid XML.

My basic question is does anyone know why using the SAXSource lost my element and attribute names and what I can do to fix this? I really do not want to use the DOMSource because my real XML files are huge and I didn't want to have to read the entire document into memory.

Thanks!
Kelly
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. Here's a little program that I wrote to test that:It does an identity transformation and it works just fine. I didn't assign an EntityResolver to the XMLReader but I don't see why that would have any effect.

Were there any namespaces in the real XML that you had the problem with? I ask because, if you look at the API documentation for org.xml.sax.ContentHandler, specifically the startElement() method, you'll see a lot of information about when the local name and/or the qualified name are passed to that method. It just seemed to me that if the SAXSource was assuming it would get one of those parameters, but the parser wasn't actually passing that parameter, then the SAXSource wouldn't have anything for its element names.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modifed my program to what you have above and scaled my XML down to simple XML (no DTD reference or ENTITYs) and the resulting XML was correct.

Then, I put everything back and it does not work.

To my XML, I added:



My program code now looks like:



Kelly
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works fine for me with Xalan-J 2.7 and JDK 1.4.2_11.
What is your CLASSPATH ?
I have not yet used 1.5

- m
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I have JAVA_HOME set to my jre1.5.0_05 directory and that is it. I do not set anything JAVA specific on my CLASSPATH or PATH. In other words, if I enter "SET CLASSPATH" at a prompt, I only see the location of my application classes and if I enter "SET PATH" at a prompt, I only see what a Windows install would have put there.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some good news. I determined that if I set namespaces aware to true on the SAX parser, my element and attribute names are generated. Yippee!!!

On the other hand, I noticed that my DOCTYPE and ENTITY references disappeared. So now I need to figure out how to retain that information in an XSLT transformation. Any ideas?

Kelly
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently "How do I get XSLT to preserve entities?" is a FAQ, based on the hits I got from Google for "xslt preserve entities". I will let Bob DuCharme give you the whole story.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! I happen to run across his first article yesterday (referenced by the page at the link you provided above). Unfortunately, it is not exactly what I'm trying to do and therefore does not work for me but I put the blame on me for not communicating this well.



Technically, I don't care if the XSLT transformation replaces &elm2Text; because I don't lose information. However, I lose information regarding elm1Obj because it is an attribute of type ENTITY and its reference is stripped out. I'm thinking I'm going to have to have my XSLT replace object="elm1Obj" with object="my.jpg".

Kelly
 
reply
    Bookmark Topic Watch Topic
  • New Topic