English 中文(简体)
Trouble parsing self concluding XML tags using SAX parser
原标题:Trouble parsing self closing XML tags using SAX parser
  • 时间:2010-04-25 07:46:28
  •  标签:
  • java
  • sax

我在使用SAX进行自我关闭的XML标签方面遇到麻烦。 我正试图从谷歌基亚普朗斯基地提取连接点。 我在平息固定的标签方面取得了合理的成功。

这里是xml的ni。

<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&amp;icep_vectorid=263602&amp;kwid=1&amp;mtid=691&amp;crlp=1_263602&amp;icep_item_id=170468125748&amp;itemid=170468125748 />
.
.

页: 1

我可以总结最新消息和出版的标签,但不是链接和分类标签。

这里,我的开端和最终主宰地位

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();
   }
 }

锡尔塔宣言。

private Stack<String> xmlTags = new Stack<String>(); 

任何帮助?

这是我的第一个职位。 我希望我遵循的是规定! 感谢 to。

更正:endElement 查询。

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++;
    }
}
问题回答

What characters does is deliver the content between the XML element tags (in chunks, one chunk per method call). So if you have an XML element like

<Foo someattrib=“” />

然后,<代码>characters 确实有人叫.,因为其中没有任何内容让牧师告诉你。

如果你依赖你的特性方法,即使标签是空的,也不得不在这里打上,you正在做错的

特性方法为缓冲添加了要素案文,但启动和最终执行需要负责从缓冲中清除和阅读,因为最终内容是你知道你收到所有要素案文的地点。 如果看不到任何东西,就不应ok。

由于您在任何一种特性中都不可能有所有的内容,因此该方法中不得有任何商业逻辑。 如果是的话,你的法典在某个时候就赢得了工作。

如何执行特征,见,这一实例为。 如果你想做的是归属价值,请见





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签