SAX를 사용하여 자체 닫기 XML 태그를 구문 분석하는 데 문제가 있습니다. Google Base API에서 링크 태그를 추출하려고합니다. 정규 태그를 파싱하는 데 상당한 성공을 거두고 있습니다. 여기 SAX 파서를 사용하여 자체 닫기 XML 태그를 구문 분석하는 데 문제가 발생했습니다.
은은 XML의 조각<entry>
<id>http://www.google.com/base/feeds/snippets/15802191394735287303</id>
<published>2010-04-05T11:00:00.000Z</published>
<updated>2010-04-24T19:00:07.000Z</updated>
<category scheme='http://base.google.com/categories/itemtypes' term='Products'/>
<title type='text'>En-el1 Li-ion Battery+charger For Nikon Digital Camera</title>
<link rel='alternate' type='text/html' href='http://rover.ebay.com/rover/1/711-67261-24966-0/2?ipn=psmain&icep_vectorid=263602&kwid=1&mtid=691&crlp=1_263602&icep_item_id=170468125748&itemid=170468125748'/>
.
.
그래서 나는 업데이트 및 게시 된 태그가 아니라 링크 및 카테고리 태그를 구문 분석 할 수
에 있습니다. ..
private Stack<String> xmlTags = new Stack<String>();
어떤 도움들 여기
내의 startElement하고하는 endElement는 xmltags에 대한public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (qName.equals("title") && xmlTags.peek().equals("entry")) {
insideEntryTitle = true;
}
xmlTags.push(qName);
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
// If a "title" element is closed, we start a new line, to prepare
// printing the new title.
xmlTags.pop();
if (insideEntryTitle) {
insideEntryTitle = false;
System.out.println();
}
}
선언을 무시?
여기 내 첫 번째 게시물입니다. 나는 게시 규칙을 따라 왔으면 좋겠다. 고마워요 톤 남자들 ..
수정 : endElement
가 호출됩니다. characters
않습니다. characters
이 무엇
public void characters(char[] ch, int start, int length) throws SAXException
{
if (insideEntryTitle)
{
String url= new String(ch, start, length);
System.out.println("url="+title);
i++;
}
}
모든 블록 코드는 4 개의 공백으로 들여 쓰기해야합니다 (이번에는 내가 편집했습니다). 이것은 xml 샘플에도 적용됩니다. –
증상은 무엇입니까? 메서드 중 어느 것도 호출되지 않습니까, 아니면 하나만 호출합니까? –
명심하십시오! 시작 요소 만 호출됩니다. – sandesh