1
저는 youtube video gdata에서 키워드를 가져 오는 방법을 찾고 있습니다.gdata xml dom을 사용하여 구문 분석
XML은 뭔가를 보이는 다음 ... 인 경우
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<id>http://gdata.youtube.com/feeds/api/videos/vidid</id>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Comedy' label='Comedy'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='kw1'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='kw2'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='kw3'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='kw4'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='kw5'/>
<title type='text'>vid title</title>
...
</entry>
내가 몇 가지 물건을 잘라, 그래서 나는 다음과 같은 코드를 사용하여 제목을 얻을 수 있습니다 :
public static String getTitle(String id) throws IOException, ParserConfigurationException, XPathExpressionException, SAXException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("https://gdata.youtube.com/feeds/api/videos/" + id);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//entry/title/text()");
Object result = expr.evaluate(doc, XPathConstants.STRING);
String title = (String) result;
return title;
}
인가를 키워드를 얻으려면이 방법을 수정하는 방법이 있습니까? 위에서 언급 한 것처럼 5 개가 아닌 여러 개의 키워드가있을 수 있습니다.
이 xpath'// entry/category/@ term'을 사용하면''kw1 ','kw2 ','kw3 ','kw4 ','kw5''와 같이 모든 키워드를 얻을 수 있습니다. – RanRag
답장을 보내 주셔서 감사합니다. 나는 처음에는 그것을 제외하고 두 가지 문제가 있다는 것을 제외하고는 그것을 시도했다. 먼저 카테고리 유형 용어를 반환하고 두 번째로 각 키워드를 반환하는 방법을 실제로 모른다. 현재는 첫 번째 값만 반환합니다. – Predz
Keywork 범주 만 사용하려면'/entry/category[contains(@scheme,'keywords.cat ')]/@ term'을 사용해보십시오. 네임 스페이스에 문제가 있다면, 다음을 시도해보십시오 :'//*[local-name()='entry']/*[local-name()='category'][contains(@scheme,'keywords.cat ')]/@ term' –