android中的SAX解析程序
嗨,我有一个android应用程序,我想从xml文件中获取数据。 我已经使用了SAX解析器,但是从这里给出的这种类型的xml文件中获取数据存在一些问题,所以请为我提供解决方案 使用SAX解析解析以下xml文件 我的xml文件在这里android中的SAX解析程序,android,xml,saxparser,Android,Xml,Saxparser,嗨,我有一个android应用程序,我想从xml文件中获取数据。 我已经使用了SAX解析器,但是从这里给出的这种类型的xml文件中获取数据存在一些问题,所以请为我提供解决方案 使用SAX解析解析以下xml文件 我的xml文件在这里 <?xml version="1.0" encoding="utf-8"?> <xml> <movie> <file> <type>1</type>
<?xml version="1.0" encoding="utf-8"?>
<xml>
<movie>
<file>
<type>1</type>
<url>http://www.mauitheatre.com/</url>
<path>http://64.250.238.26:1111/clips/UlalenaSplashAdd.jpg</path>
<title>UlalenaSplash</title>
</file>
<file>
<type>0</type>
<path>http://64.250.238.26:1111/clips/BaldwinBeach.mp4</path>
<title>Baldwin Beach</title>
</file>
</movie>
<movie>
<file>
<type>0</type>
<url></url>
<path>http://64.250.238.26:1111/clips/AppTeaser.mp4</path>
<title>SlackKeyShow</title>
</file>
<file>
<type>0</type>
<path>http://64.250.238.26:1111/clips/BigBeach.mp4</path>
<title>Big Beach</title>
</file>
</movie>
<movie>
<file>
<type>1</type>
<url>http://www.mountainapplecompany.com/new-releases/keola-beamer-and-raiatea</url>
<path>http://64.250.238.26:1111/clips/raiateaADD.jpg</path>
<title>Raiatea Keola Beamer add</title>
</file>
<file>
<type>0</type>
<path>http://64.250.238.26:1111/clips/CharleyYoungBeach.mp4</path>
<title>Charley Young Beach</title>
</file>
</movie>
<movie>
<file>
<type>1</type>
<url>http://www.bennyuyetake.com</url>
<path>http://64.250.238.26:1111/clips/BennyUyetake.jpg</path>
<title>Benny Uyetake SPlash</title>
</file>
<file>
<type>0</type>
<path>http://64.250.238.26:1111/clips/HamoaBeach-1.mp4</path>
<title>Hamoa Beach</title>
</file>
</movie>
<movie>
<file>
<type>1</type>
<url>http://www.dericksebastian.com</url>
<path>http://64.250.238.26:1111/clips/DSSplash.jpg</path>
<title>DS Splash</title>
</file>
<file>
<type>0</type>
<path>http://64.250.238.26:1111/clips/HanaBay.mp4</path>
<title>Hana Bay</title>
</file>
</movie>
<movie>
<file>
<type>1</type>
<url>http://www.mountainapplecompany.com/new-releases/keola-beamer-and-raiatea</url>
<path>http://64.250.238.26:1111/clips/raiateaADD.jpg</path>
<title>Raiatea Keola Beamer add</title>
</file>
<file>
<type>0</type>
<path>http://64.250.238.26:1111/clips/KamaoleBeachPark1b-1.mp4</path>
<title>Kamaole Beach Park 1</title>
</file>
</movie>
</xml>
1.
http://www.mauitheatre.com/
http://64.250.238.26:1111/clips/UlalenaSplashAdd.jpg
乌拉伦斯普拉斯
0
http://64.250.238.26:1111/clips/BaldwinBeach.mp4
鲍德温海滩
0
http://64.250.238.26:1111/clips/AppTeaser.mp4
懒散表演
0
http://64.250.238.26:1111/clips/BigBeach.mp4
大海滩
1.
http://www.mountainapplecompany.com/new-releases/keola-beamer-and-raiatea
http://64.250.238.26:1111/clips/raiateaADD.jpg
雷亚塔基奥拉比默酒店
0
http://64.250.238.26:1111/clips/CharleyYoungBeach.mp4
查理杨海滩酒店
1.
http://www.bennyuyetake.com
http://64.250.238.26:1111/clips/BennyUyetake.jpg
Benny Uyetake飞溅
0
http://64.250.238.26:1111/clips/HamoaBeach-1.mp4
哈默阿海滩
1.
http://www.dericksebastian.com
http://64.250.238.26:1111/clips/DSSplash.jpg
DS飞溅
0
http://64.250.238.26:1111/clips/HanaBay.mp4
哈纳湾
1.
http://www.mountainapplecompany.com/new-releases/keola-beamer-and-raiatea
http://64.250.238.26:1111/clips/raiateaADD.jpg
雷亚塔基奥拉比默酒店
0
http://64.250.238.26:1111/clips/KamaoleBeachPark1b-1.mp4
卡茂勒海滩公园1
问题可能是
标记未关闭。要能够解析文件,它必须是格式良好的XML文件,因此请尝试在末尾添加
,然后再试一次。问题可能是
标记没有关闭。为了能够解析该文件,它必须是格式良好的XML文件,因此请尝试在末尾添加
,然后再试一次。假设您需要数组列表,其中Movie
类的结构是
public class Movie
{
private ArrayList<File> files;
public Movie()
{
this.files = new ArrayList<File>();
}
}
使用必要的getter
和setter
函数,您可以通过
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
final MovieXmlHandler handler = new MovieXmlHandler();
parser.parse(new InputSource(new StringReader(yourXmlString)), handler);
final ArrayList<Movie> movies = handler.getRecords();
当然,如果您只有xml数据的url(xmlUrl:String
),那么可以使用
final URL sourceUrl = new URL(xmlURL);
final SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
final XMLReader reader = sp.getXMLReader();
final MovieXmlHandler handler = new MovieXmlHandler();
reader.setContentHandler(handler);
reader.parse(new InputSource(sourceUrl.openStream()));
final ArrayList<Movie> movies = handler.getRecords();
如果这不是您想要的,请告诉我们。假设您需要一个ArrayList
,其中Movie
类的结构是
public class Movie
{
private ArrayList<File> files;
public Movie()
{
this.files = new ArrayList<File>();
}
}
使用必要的getter
和setter
函数,您可以通过
final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
final MovieXmlHandler handler = new MovieXmlHandler();
parser.parse(new InputSource(new StringReader(yourXmlString)), handler);
final ArrayList<Movie> movies = handler.getRecords();
当然,如果您只有xml数据的url(xmlUrl:String
),那么可以使用
final URL sourceUrl = new URL(xmlURL);
final SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
final XMLReader reader = sp.getXMLReader();
final MovieXmlHandler handler = new MovieXmlHandler();
reader.setContentHandler(handler);
reader.parse(new InputSource(sourceUrl.openStream()));
final ArrayList<Movie> movies = handler.getRecords();
如果这不是您想要的,请告诉我们。真正的问题是您自己正在尝试使用SAX解析器;这让生活变得更加艰难。如果可能的话,为什么不依赖基于注释的XML解析框架,比如库呢
我刚刚写了一篇文章。真正的问题是您自己正在尝试使用SAX解析器;这让生活变得更加艰难。如果可能的话,为什么不依赖基于注释的XML解析框架,比如库呢
我刚写了一封信。你能粘贴错误吗?否则很难找出问题所在。请分享您的解析器实现,让我们看看哪里会出错。谢谢你能粘贴错误吗?否则很难找出问题所在。请分享您的解析器实现,让我们看看哪里会出错。谢谢xml标记实际上已关闭,但格式不正确。@rekaszeru:好的,那么我们需要更多信息;)xml标记实际上已关闭,但格式不正确。@rekaszeru:好的,那么我们需要更多信息;)