javax.xml.transform

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

javax.xml.transform

Postby xspotlivin » Sun Apr 05, 2009 10:22 pm

I need to use the transform package (transformer, transformfactory, etc.) so that I can convert an xml node to a new document. However, when I try to import the package, it says that it cannot be resolved. Are you not allowed to use this package on Android?

Below is the code subset of how I want to transform:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import javax.xml.transform.Transformer;
  2.  
  3. import javax.xml.transform.*;
  4.  
  5. import javax.xml.transform.dom.DOMResult;
  6.  
  7. import javax.xml.transform.dom.DOMSource;
  8.  
  9.  
  10.  
  11. Node adherenceIntervals = reportXML.getFirstChild().getFirstChild();
  12.  
  13. TransformerFactory tf = TransformerFactory.newInstance();
  14.  
  15. Transformer xf = tf.newTransformer();
  16.  
  17. DOMResult dr = new DOMResult();
  18.  
  19. xf.transform(new DOMSource(adherenceIntervals), dr);
  20.  
  21. Document adherenceIntervalsDoc = (Document) dr.getNode();
  22.  
  23.        
  24.  
  25. NodeList medicationNodes = adherenceIntervalsDoc.getElementsByTagName("Medication");
  26.  
  27. int medicationLength = medicationNodes.getLength();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Any thoughts?
xspotlivin
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 26, 2009 8:15 am
Location: Cambridge, MA

Top

Postby xspotlivin » Mon Apr 06, 2009 1:07 am

I solved this. I was trying to do way to much work. Simple solution:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Node adherenceIntervals = reportXML.getFirstChild().getFirstChild();
  2.  
  3. Element adherenceIntervalsElement = (Element) adherenceIntervals;
  4.  
  5.        
  6.  
  7. NodeList medicationNodes = adherenceIntervalsElement.getElementsByTagName("Medication");
  8.  
  9. int medicationLength = medicationNodes.getLength();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
xspotlivin
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 26, 2009 8:15 am
Location: Cambridge, MA

Postby xspotlivin » Mon Apr 06, 2009 2:44 am

Actually, this does not work when I ran the code on the emulator. It worked in a separate testing program I have. Back to step 1.
xspotlivin
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 26, 2009 8:15 am
Location: Cambridge, MA

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: MSNbot Media and 3 guests