XML을 구문 분석하는 Java 프로그램을 프로그래밍하고 있습니다. 내 문제는 ä
, ö
, ü
과 같은 특수 기호가 내 응용 프로그램에 표시되지 않는다는 것입니다. 그러나 나머지 텍스트는 아직 없습니다. 예 :XML 구문 분석 ööü Java
Oliver Krähnbühl => Oliver Krhnbhl
XML 코딩으로는 어떤 작업도 수행 할 수 없습니다. HTTP 요청에 의해로드되기 때문입니다.
public Boolean parse(String url) {
try {
InputStream inStream = (InputStream) new URL(url).getContent();
// TODO: after we must do a cache of this XML!!!!
this.factory = DocumentBuilderFactory.newInstance();
this.builder = this.factory.newDocumentBuilder();
this.builder.isValidating();
Document doc = this.builder.parse(inStream, null);
doc.getDocumentElement().normalize();
//Get all categories
NodeList categoryList = doc.getElementsByTagName("Category");
//Loop each category
for (int i = 0; i < categoryList.getLength(); i++) {
//Get categoryname
final NamedNodeMap attr = categoryList.item(i).getAttributes();
final String categoryName = getNodeValue(attr, "name");
//Add a category separator
productSeparator s = new productSeparator(categoryName);
this.list.add(s);
//Get current Category as element
Element category = (Element)categoryList.item(i);
//Get all Products from current category
NodeList productList = category.getElementsByTagName("Product");
//Loop each element from each category
for(int x = 0; x < productList.getLength(); x++)
{
//Get current Product as element
Element product = (Element)productList.item(x);
//Set properties to variable
String productName = (((Element)product.getElementsByTagName("Name").item(0)).getChildNodes()).item(0).getNodeValue();
String productDescription = (((Element)product.getElementsByTagName("Description").item(0)).getChildNodes()).item(0).getNodeValue();
String productPrice = (((Element)product.getElementsByTagName("Price").item(0)).getChildNodes()).item(0).getNodeValue();
String productImageUri = (((Element)product.getElementsByTagName("ImageUri").item(0)).getChildNodes()).item(0).getNodeValue();
// Construct Country object
product p = new product(productName, productDescription, new Float(productPrice), productImageUri);
// Add to list
this.list.add(p);
}
}
return true;
}
catch (Exception er) {
Log.e("Exception", er.toString());
return false;
}
}
XML (및 해당 인코딩), 구문 분석 코드 및 코드 disp 누워 있으면 대답하기 어려울 것입니다. –
이상 하네. 그것은 내 애플 리케이션에서 작동합니다. 어쩌면 XML 문서를 구문 분석하고 표시하는 코드를 게시해야합니다. –
인코딩을 확인하십시오 – nidhin