다음 XML이 있는데 일부 노드의 값을 인쇄하려고합니다. 예를 들어, 다음 코드를 사용하여 "200812 라이브 bigfish" Java : XML 파일을 구문 분석하는 동안의 문제
내가 무슨 일을하고있는 중이 야 나는NodeList list = doc.getElementsByTagName("photo");
element = (Element)list.item(0);
list = element.getChildNodes();
System.out.println(list.item(0).getNodeName());
System.out.println(list.item(0).getNodeValue());
을 인쇄 할 내가 대신 "제목"과의
null
#text
를 얻을? 감사
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photo id="2882550369" secret="21054282c8" server="3106" farm="4" dateuploaded="1222202793" isfavorite="0" license="0" safety_level="0" rotation="0" views="5" media="photo">
<owner nsid="[email protected]" username="fishthemusic" realname="masayoshi yamamiya" location="kawasaki, japan" iconserver="4" iconfarm="1" />
<title>bigfish live 200812</title>
<description>photo by Kazuhiro Nakamura</description>
<visibility ispublic="1" isfriend="0" isfamily="0" />
<dates posted="1222202793" taken="2008-09-24 05:46:33" takengranularity="0" lastupdate="1222998937" />
<editability cancomment="1" canaddmeta="0" />
<publiceditability cancomment="1" canaddmeta="0" />
<usage candownload="1" canblog="1" canprint="0" canshare="1" />
<comments>0</comments>
<notes />
<tags>
<tag id="314160-2882550369-80673" author="[email protected]" raw="bigfish" machine_tag="0">bigfish</tag>
<tag id="314160-2882550369-5558" author="[email protected]" raw="live" machine_tag="0">live</tag>
<tag id="314160-2882550369-29726586" author="[email protected]" raw="upcoming:event=1167424" machine_tag="1">upcoming:event=1167424</tag>
</tags>
<urls>
<url type="photopage">http://www.flickr.com/photos/fishthemusic/2882550369/</url>
</urls>
</photo>
</rsp>
나는 그가 getChildNodes의 속성을 받고있다 생각하지 않는다 작동하지만, 그는 공백 문자 텍스트 노드를 받고있다. –
XML은'<[[CDATA]]>' –
@Travis 안에 있지 않으면 공백을 무시합니다. 그건 사실이 아닙니다. 우선 DOM의 Element 노드의 애트리뷰트는 아닌 것으로 간주되며 두 번째로 공백은 기본적으로 무시되지 않습니다. CDATA는 문법적인 설탕 일 뿐이며 공백과는 특별한 관계가 없습니다. –