1 21 22 package nu.xom.samples; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.InputStream ; 26 27 import nu.xom.Builder; 28 import nu.xom.Document; 29 import nu.xom.Element; 30 import nu.xom.ParsingException; 31 import nu.xom.ProcessingInstruction; 32 33 34 45 public class PseudoAttributes { 46 47 public static Element getAttributes(ProcessingInstruction pi) 48 throws ParsingException { 49 50 StringBuffer sb = new StringBuffer ("<"); 51 sb.append(pi.getTarget()); 52 sb.append(" "); 53 sb.append(pi.getValue()); 54 sb.append("/>"); 55 56 try { 57 InputStream in = new ByteArrayInputStream (sb.toString().getBytes("UTF-8")); 58 Builder parser = new Builder(); 59 60 Document doc = parser.build(in); 63 Element root = doc.getRootElement(); 64 doc.setRootElement(new Element("fauxRoot")); 66 return root; 67 } 68 catch (Exception ex) { 69 throw new ParsingException(pi.toXML() 70 + " is not in pseudo-attribute format.", ex); 71 } 72 73 } 74 75 } 76 | Popular Tags |