sax

Android心得3.2--用SAX解析器解析xml文件内容

大兔子大兔子 提交于 2020-03-01 12:09:58
一. 在Android 平台上可以使用Simple API for XML(SAX) 、 Document Object Model(DOM)和Android附带的pull解析器解析XML文件。 本例子要解析的XML文件: 文件名称:itcast.xml <?xml version="1.0" encoding="UTF-8"?> <persons> <person id="23"> <name>李明</name> <age>30</age> </person> <person id="20"> <name>李向梅</name> <age>25</age> </person> </persons> 下面这个例子定义了一个javabean用于存放上面解析出来的xml内容, 这个javabean为Person。 public class Person { private Integer id; private String name; private Short age; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name)

bug解决:org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

半腔热情 提交于 2020-02-06 08:02:36
Caused by: org.xml.sax. SAXParseException ; lineNumber: 2 ; columnNumber: 6 ; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。 at [图片]com.sun.org.apache.xerces. internal .util. ErrorHandlerWrapper .createSAXParseException( Unknown Source ) at [图片]com.sun.org.apache.xerces. internal .util. ErrorHandlerWrapper . fatalError ( Unknown Source ) at [图片]com.sun.org.apache.xerces. internal .impl. XMLErrorReporter .reportError( Unknown Source ) at [图片]com.sun.org.apache.xerces. internal .impl. XMLErrorReporter .reportError( Unknown Source ) at [图片]com.sun.org.apache.xerces. internal .impl. XMLScanner .reportFatalError(

SAX parser ignores text because of a <br /> tag

本小妞迷上赌 提交于 2020-01-26 04:25:06
问题 have a slight problem here and I don't know how to fix it. I have an XML file that looks like this: <?xml version="1.0"?> <item> <title>Item 1</name> <description>Description Text 1<br />Description Text 2</description> </item> And I have a SAX parser that looks like this: public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if ("item".equals(qName)) { currentItem = new Item(); } else if ("title".equals(qName)) { parsingTitle = true

How to ignore inline DTD when parsing XML file in Java

北慕城南 提交于 2020-01-23 08:05:26
问题 I have a problem reading a XML file with DTD declaration inside (external declaration is solved). I'm using SAX method (javax.xml.parsers.SAXParser). When there is no DTD definition parsing looks like for example StartEement-Characters-StartElement-Characters-EndElement-Characters...... So there is characters method called immediately after Start or End element and thats how I need it to be. When DTD is in file parsing schema changes to for example StartElement-StartElement-StartElement

SAX: How to get the content of an element

最后都变了- 提交于 2020-01-22 20:19:28
问题 I have some trouble understanding parsing XML structures with SAX. Let's say there is the following XML: <root> <element1>Value1</element1> <element2>Value2</element2> </root> and a String variable myString . Just going through with the methods startElement, endElement() and characters() is easy. But I don't understand how I can achieve the following: If the current element equals element1 store its value value1 in myString . As far as I understand there is nothing like: if (qName.equals(

How to tell Java SAX Parser to ignore invalid character references?

家住魔仙堡 提交于 2020-01-22 17:14:25
问题 When trying to parse incorrect XML with a character reference such as &#x1 , Java's SAX Parser dies a horrible death with a fatal error such as org.xml.sax.SAXParseException: Character reference "&#x1" is an invalid XML character. Is there any way around this? Will I have to clean up the XML file before I hand it off to the SAX Parser? If so, is there an elegant way of going about this? 回答1: Use XML 1.1! skaffman is completely right, but you can just stick <?xml version="1.1"?> on the top of

SAX XML Parsing in android

℡╲_俬逩灬. 提交于 2020-01-21 18:23:27
问题 XML Code is <?xml version="1.0" encoding="UTF-8" ?> <opml version="1"> <head> <title>Radio</title> <status>200</status> </head> <body> <outline type="link" text="Local" URL="http://..............." key="local" /> <outline type="link" text="Music" URL="http://.............." key="music" /> <outline type="link" text="walk" URL="http://...................." key="walk" /> <outline type="link" text="Sports" URL="http://..........." key="sports" /> <outline type="link" text="Place" URL="http://....

Using SAX to parse common XML elements

断了今生、忘了曾经 提交于 2020-01-19 04:01:13
问题 I'm currently using SAX (Java) to parse a a handful of different XML documents, with each document representing different data and having slightly different structures. For this reason, each XML document is handled by a different SAX class (subclassing DefaultHandler ). However, there are some XML structures that can appear in all these different documents. Ideally, I'd like to tell the parser "Hey, when you reach a complex_node element, just use ComplexNodeHandler to read it, and give me

Parsing Mixed-Content XML with SAX

人盡茶涼 提交于 2020-01-17 03:26:06
问题 I have a sample mixed-content XML document (structure cannot be modified): <items> <item> ABC123 <status>UPDATE</status> <units> <unit Description="Each ">EA <saleprice>2.99</saleprice> <saleprice2/> </unit> </units> <warehouses> <warehouse>100<availability>2987.000</availability> </warehouse> </warehouses> </item> </items> I am attempting to use SAX parser on this XML document, but the mixed-content elements are causing some issues. Namely, I get an empty String returned when attempting to

Parse Xml to get attribute value in android using android SAX packages mathods

只愿长相守 提交于 2020-01-15 12:48:10
问题 I am parsing an XML file in which certain element having attributes. Is there any way to get the attribute value using methods given in android SAX package? 回答1: Here's my real answer. :) You probably meant android.sax. Then you need to add a StartElementListener and in start() you'll find your Attributes. 来源: https://stackoverflow.com/questions/6070674/parse-xml-to-get-attribute-value-in-android-using-android-sax-packages-mathods