alibaba82
16 years agoSuper Contributor
Error While parsing XML file using groovy
Hello,
I have a URL which returns a page in XML. I have some groovy code that writes the XML locally to a file and then parses this file to store certain element to a database.
The code is
Object ReturnTopXAA(int num)
{
def address = AATopXItems + num.toString()
def file = new FileOutputStream("AAXResults.xml")
def out = new BufferedOutputStream(file)
out << new URL(address).openStream()
out.close()
//Parse XML From AAResults.xml
def records = new XmlSlurper().parse(new File("AAXResults.xml"))
def recordsSize = records.response.items.item.id.size()
def ItemsList = [];
for (i in 0..recordsSize-1)
ItemsList.add(records.response.items.item.id)
return ItemsList;
}
This code works fine upto returning 478 items. However if I try to return any more I get the following error.
apache xerces malformedbytesequenceexception invalid byte 2 of 3-byte utf-8 sequence
Any idea what I can do to fix this.
Thanks
Ali
I have a URL which returns a page in XML. I have some groovy code that writes the XML locally to a file and then parses this file to store certain element to a database.
The code is
Object ReturnTopXAA(int num)
{
def address = AATopXItems + num.toString()
def file = new FileOutputStream("AAXResults.xml")
def out = new BufferedOutputStream(file)
out << new URL(address).openStream()
out.close()
//Parse XML From AAResults.xml
def records = new XmlSlurper().parse(new File("AAXResults.xml"))
def recordsSize = records.response.items.item.id.size()
def ItemsList = [];
for (i in 0..recordsSize-1)
ItemsList.add(records.response.items.item.id)
return ItemsList;
}
This code works fine upto returning 478 items. However if I try to return any more I get the following error.
apache xerces malformedbytesequenceexception invalid byte 2 of 3-byte utf-8 sequence
Any idea what I can do to fix this.
Thanks
Ali