所以我读了一个XML。当我的标签包含这么短的项目时,我能够成功读取没有问题:
<Building>
<location_id>7</location_id>
<location_name>Enrique Razon Building</location_name>
<location_description>Land of Sports</location_description>
<location_icon_name>pink_trees</location_icon_name>
<location_hasVisited>false</location_hasVisited>
<building_image>leaves1</building_image>
</Building>
但是,当我的标签之间有长文本时......
<Building>
<location_id>8</location_id>
<location_name>St. Miguel Hall (College of Liberal Arts)</location_name>
<location_description>
Dean: Dr. Dominador F. Bombongan, Jr.
Vice Dean: Dr. Feorillo Petronillo Demeterio III
Background
Constructed on 1969, Miguel Hall was named after one of the three Lasallian Brothers-Saints – St. Miguel Francisco Febres Cordero of Ecuador, canonized by the Servant of God Pope John Paul II.
1st Floor
CE-Construction Technology and Management (CTM) Research Laboratory / Interdisciplinary Research Room (M101)
CE-Survey Equipment Room (M102)
CE-Geotechnical Engineering Laboratory (M103A)
CE-Hydraulics and Water Resources Laboratory (M103B)
Construction Technology and Management Laboratory (M104A)
Center for Microhydro for Rural Electrification CeMTRE (M104B)
ECE Thesis Room (M104D)
Transportation Laboratory (M104E)
Intelligence Systems Laboratory (ISL) (M106)
Foundry and Welding Area (M107)
Air conditioning Control Room (M109)
Mechanical Engineering Lab Coordinators Office (M110)
M.E. Technicians Office/Stockrom (M111)
Fuel and Lubrication Lab (M112)
Lecture Room (M113)
Water Resource Laboratory/Flow Analysis Laboratory (M114)
Mechanical Engineering Department (M105-M107, M115)
Civil Engineering Lab, ECE Thesis Room (M112)
Electronics and Communications Engineering Department (M116)
CE-HWR Research Office (M154)
CE-GTE Research Office (M155)
CE-Laboratory Development and Coordination Office (M156)
Power and Thermodynamics Laboratory
2nd Floor
BNSCWC ASEAN Literatures Reading Room
Desktop Laboratory (M204)
Person in charge: Jay Magoncia
For Communication Arts and Organization Communication majors
Houses computer terminals where the students are taught to layout their own print materials.
Lecture Room (M205-M206)
Viewing Room of Communications Department (M208)
Department of Communication (M209)
Chair: Dr. Maria Angeli H. Diaz
Bienvenido N. Santos Creative Writing Center (M210)
Established with the intention of formalizing and implementing the University’s objectives of contributing to the literary development of the country, and improving the literary skills and expertise of La Salle students, faculty and non-teaching staff.
Radio and Television/Studio Laboratory (M211)
Technician: Ricardo Macapuno
Boasts of equipment which will help you in producing your own Radio programs. The Television Lab is equipped with TV cameras used to produce and air TV programs. It also has a blue screen which makes it possible to create special effects on your videos.
There is also an editing suite inside the lab where you can do non-linear editing for your video projects. This lab however is open only to students enrolled in communication lab courses.
The Radio and Television Lab may also be used when you have a photo shoot or a video shoot.
Television Studio (M212)
The room has various lights, cameras and other equipment that students can use to complete their projects.
For Communication Arts and Organization Communication majors.
CLA Dean and Vice Dean’s Office (M214)
Photography Laboratory (M215)
Technician: Ferdinand Pascua
Photography Labs: black and white and colored photography rooms
Inside the dark room you can enlarge your own black and white photos and process your negatives
Photography Laboratory and Workshop (M216)
Technician: Norman Loteria
FULLY FUNCTIONAL
Equipment Room (M217)
Technician: Edgar Sta. Ana
Equipped with SLR cameras and tripods which student’s can borrow
Center for Educational Multimedia (CREM) (M218-M219)
Training for educational multimedia, printing and scanning services for faculty
Video Production Workshop (M220, M221)
Video Editing Bay: Norman Loteria
This room houses about 20 TV’s and VHS players to facilitate linear editing.
It also serves as a viewing room for classes.
3rd Floor
Custodial Room (M302)
Faculty Dining Room (M301)
The Phinma E-Classroom (M306)
Donated by PHINMA Group of Companies and Mariposa Foundation Inc.
Inaugurated on Nov. 21, 2002, this state-of-the-art classroom is designed with videoconferencing to develop the students’ exposure with other foreign and local students and technology.
Nursery School (M312)
Lecture Rooms (M308, M310-M311, M313-M321)
4th Floor
Chemistry Laboratory and Lecture Room (M404)
Electrical Machine Laboratory (M406A)
Electric Circuit Laboratory (M406B-M406C)
IMS Viewing Room (M410)
90 seat capacity
Boasta of a video projection-VHS format with data converter, overhead projection, opaque projection, slide projection, public address system, Yamaha home theater sound system
Product Design and Development Laboratory (M413)
Robotics and Automation Laboratory (M416)
Lecture Rooms (M417-M421)
Trivia
- Formerly known as the St. Benilde Hall and before the split of the College of Arts and Sciences, Miguel Building was part of the College of Engineering.
- The first computers ever used in DLSU was situated in the Miguel Building – punch cards and yellow paper tape.
- The Comm Arts Television Studio was a gift of the Japanese people through the Commemorative Association for the Japan World Exposition.
- Houses some labs for the College of engineering because it was an engineering building before and the equipment are too heavy to transfer to Velasco Hall so they retained the labs.
</location_description>
<location_icon_name>pink_trees</location_icon_name>
<location_hasVisited>false</location_hasVisited>
<building_image>pattern1</building_image>
</Building>
我的代码失败,解析器没有读取整个内容并停在location_description中第三行的某处。
有没有办法让我的解析器读取里面的所有文本?这是我目前的解析器:
public static Building[] getBuildings(Context ctxt) {
XmlPullParserFactory factory;
ArrayList<Building> buildings = new ArrayList<>();
Building currBuilding = null;
String currText = "";
try {
//Get our factory and pull parser
factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
// Open up InputStream and Reader of our file.
AssetManager assetManager = ctxt.getAssets();
InputStream fis = assetManager.open("Buildings.xml");
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
//point parser to our file
xpp.setInput(reader);
//get initial eventType
int eventType = xpp.getEventType();
//loop until end of event
while (eventType != XmlPullParser.END_DOCUMENT) {
// Get the current tag
String tagname = xpp.getName();
// React to different event types appropriately
switch (eventType) {
case XmlPullParser.START_TAG:
if (tagname.equalsIgnoreCase(KEY_BUILDING)) {
// If we are starting a new <Building> block we need
//a new StackSite object to represent it
currBuilding = new Building();
}
break;
case XmlPullParser.TEXT:
//grab the current text so we can use it in END_TAG event
currText = xpp.getText();
Log.e("TAG", currText);
break;
case XmlPullParser.END_TAG:
if (tagname.equalsIgnoreCase(KEY_BUILDING)) {
// if </Building> then we are done with current Building
// add it to the list.
buildings.add(currBuilding);
} else if(tagname.equalsIgnoreCase(KEY_LOCATION_ID)){
currBuilding.setLocId(Integer.parseInt(currText));
}
else if (tagname.equalsIgnoreCase(KEY_LOCATION_NAME)) {
// if </location_name> use setName() on currBuilding
currBuilding.setName(currText);
} else if (tagname.equalsIgnoreCase(KEY_LOCATION_DESCRIPTION)) {
// if </location_description> use setDescription() on currBuilding
currBuilding.setDescription(currText);
} else if (tagname.equalsIgnoreCase(KEY_LOCATION_ICON_NAME)) {
// if </location_icon_name> use setIconName() on currBuilding
currBuilding.setIconName(currText);
} else if (tagname.equalsIgnoreCase(KEY_LOCATION_HASVISITED)) {
// if </location_hasVisited> use setHasVisited() on currBuilding
if(currText.contentEquals("true"))
{
currBuilding.setHasVisited(true);
}
else currBuilding.setHasVisited(false);
} else if (tagname.equalsIgnoreCase(KEY_BUILDING_MAP_IMAGE)) {
currBuilding.setMapImage(currText);
}
break;
default:
break;
}
//move on to next iteration
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return buildings.toArray(new Building[buildings.size()]);
}
感谢您阅读这篇文章!谢谢你的帮助!!! :) 编辑:替换&#39;&amp;&#39;与&#39;和&#39;,工作!!!我只是没有正确地检查对不起!
答案 0 :(得分:0)
解析器是不是在阅读&#39;&amp;&#39;在文中正确吗?这些应该编码......
替换&#39;&amp;&#39;与&