读取html带自定义标签问题,TagHandler TagHandler自定义标签html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看起来是这个效果,我想拿到color里面的值,这个得不到。 看起来是这个效果,我想拿到color里面的值,这个得不到。研究了会,感觉有点奇怪啊。看看源码先 String s = "<g color='blue'>自定义</g>"; try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); MyContentHandler sss = new MyContentHandler(); reader.setContentHandler(sss); reader.parse(new InputSource(new StringReader(s))); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.Locator;import org.xml.sax.SAXException;public class MyContentHandler implements ContentHandler { private StringBuffer buf; public void setDocumentLocator( Locator locator ) { } public void startDocument() throws SAXException { buf=new StringBuffer(); System.out.println("*******开始解析文档*******"); } public void endDocument() throws SAXException { System.out.println("*******解析文档结束*******"); } public void processingInstruction( String target, String instruction ) throws SAXException { } public void startPrefixMapping( String prefix, String uri ) { System.out.println("\n前缀映射: " + prefix +" 开始!"+ " 它的URI是:" + uri); } public void endPrefixMapping( String prefix ) { System.out.println("\n前缀映射: "+prefix+" 结束!"); } public void startElement( String namespaceURI, String localName, String fullName, Attributes attributes ) throws SAXException { System.out.println("\n 元素: " + "["+fullName+"]" +" 开始解析!"); // 打印出属性信息 for ( int i = 0; i < attributes.getLength(); i++ ) { System.out.println("\t属性名称:" + attributes.getLocalName(i) + " 属性值:" + attributes.getValue(i)); } } public void endElement( String namespaceURI, String localName, String fullName ) throws SAXException { //打印出非空的元素内容并将StringBuffer清空 String nullStr=""; if (!buf.toString().trim().equals(nullStr)){ System.out.println("\t内容是: " + buf.toString().trim()); } buf.setLength(0); //打印元素解析结束信息 System.out.println("元素: "+"["+fullName+"]"+" 解析结束!"); } public void characters( char[] chars, int start, int length ) throws SAXException { //将元素内容累加到StringBuffer中 buf.append(chars,start,length); } public void ignorableWhitespace( char[] chars, int start, int length ) throws SAXException { } public void skippedEntity( String name ) throws SAXException { }}这样是可以解析出来的,color的属性放在Attributes中了,但是我看源码里,如果是自定义的tag,解析时却不用这个Attributes,不知为何 没测试你这个又没用但是我找到的其他的方法http://blog.csdn.net/q445697127/article/details/38348031其实xmlReader里面有属性,用反射得到那些值 安卓新手求教个如何在mapabc中的MapView中实现双击事件? 怎么让弹出窗口弹出后弹窗上面的编辑框有焦点 在手机上安装了自己开发的程序,却弹出“该连接程序不再被安装到手机上”! 我是菜鸟,求帮忙 怎么转调到其他模块的activity mm时弹出MountManager 求助:用ant打包的时候,为什么没有把jni的.so文件打包进来啊 android和J2EE选哪个? Socket通讯消息接收问题 请问可以用opencv4android实现两张图片相似度的对比吗?怎么实现呢? 哪位大侠能提供一个jni访问sqlite数据库的例子? [新手求助]Service小程序运行出错
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
MyContentHandler sss = new MyContentHandler();
reader.setContentHandler(sss);
reader.parse(new InputSource(new StringReader(s)));
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
public class MyContentHandler implements ContentHandler {
private StringBuffer buf;
public void setDocumentLocator( Locator locator ) {
}
public void startDocument() throws SAXException {
buf=new StringBuffer();
System.out.println("*******开始解析文档*******");
}
public void endDocument() throws SAXException {
System.out.println("*******解析文档结束*******");
}
public void processingInstruction( String target, String instruction )
throws SAXException {
}
public void startPrefixMapping( String prefix, String uri ) {
System.out.println("\n前缀映射: " + prefix +" 开始!"+ " 它的URI是:" + uri);
}
public void endPrefixMapping( String prefix ) {
System.out.println("\n前缀映射: "+prefix+" 结束!");
}
public void startElement( String namespaceURI, String localName,
String fullName, Attributes attributes )
throws SAXException {
System.out.println("\n 元素: " + "["+fullName+"]" +" 开始解析!");
// 打印出属性信息
for ( int i = 0; i < attributes.getLength(); i++ ) {
System.out.println("\t属性名称:" + attributes.getLocalName(i)
+ " 属性值:" + attributes.getValue(i));
}
}
public void endElement( String namespaceURI, String localName,
String fullName )
throws SAXException {
//打印出非空的元素内容并将StringBuffer清空
String nullStr="";
if (!buf.toString().trim().equals(nullStr)){
System.out.println("\t内容是: " + buf.toString().trim());
}
buf.setLength(0);
//打印元素解析结束信息
System.out.println("元素: "+"["+fullName+"]"+" 解析结束!");
}
public void characters( char[] chars, int start, int length )
throws SAXException {
//将元素内容累加到StringBuffer中
buf.append(chars,start,length);
}
public void ignorableWhitespace( char[] chars, int start, int length )
throws SAXException {
}
public void skippedEntity( String name ) throws SAXException {
}
}这样是可以解析出来的,color的属性放在Attributes中了,但是我看源码里,如果是自定义的tag,解析时却不用这个Attributes,不知为何
其实xmlReader里面有属性,用反射得到那些值