2013-02-07 30 views
-4

如何使用DOM解析此標記?使用Dom的Android,java,Xml Parsin

<gd:where startTime="Jan 4 2012" endTime="Jan 5 2012"/>

我想從這個標籤startTimeendTime

+0

你有什麼atm?你甚至可以使用正則表達式來做到這一點 –

+0

不,我無法解析gd:當 –

+0

我想從這個網址解析xml google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/...它返回給我一個XML,我用Dom解析它我可以很容易地從這個XML中挑選標題。但是當我嘗試解析標記它不起作用 –

回答

0

嘗試使用此

getAttributeValue(null,"startTime") 
+0

我想從此URL解析xml http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/基本 它返回我一個XML,我解析它使用Dom 我可以很容易地從這個XML中挑選標題。 但是當我試圖解析標籤它不工作 –

+0

使用任何解析器? –

+0

是這是我在做什麼 網址URL =新的URL( \t \t \t 「http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic」) ; \t DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); \t DocumentBuilder db = dbf.newDocumentBuilder(); \t Document doc = db.parse(new InputSource(url.openStream())); \t doc.getDocumentElement()。normalize(); –

0

編寫XML解析器是非常有益的,但如果您有命名空間的煩惱。我會建議使用現有的XML解析庫。

如果你想知道,搜索解析XML元素名稱空間

simplexmlxpath應該都工作得不錯。