0
현재 Java의 작은 날씨 API (YR.NO에서) 작업 중입니다.Java - 부모 자식의 attributevalue
API는 다음과 같이 XML 형식입니다.
참고 : 같은 API에 여러 개의 "상자"가 있지만 그 위에 다른 시간이 있습니다. 이와
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException
{
for (int i = 0; i < attributes.getLength(); i++)
{
String attributeName = attributes.getLocalName(i);
String attributeValue = attributes.getValue(i);
System.out.println(attributes.getLocalName(i) + " : " + attributes.getValue(i));
//if(attributeValue.toLowerCase().indexOf(timeCheck.toLowerCase()) != -1)
// {
// System.out.println("Temperature: " + attributes.getValue(i));
// }
}
<time datatype="forecast" from="2016-09-08T21:00:00Z" to="2016-09-08T21:00:00Z">
<location altitude="47" latitude="59.3293235" longitude="18.0685808">
<temperature id="TTT" unit="celsius" value="12.0"/>
<windDirection id="dd" deg="121.8" name="SE"/>
<windSpeed id="ff" mps="2.2" beaufort="2" name="Svak vind"/>
<windGust id="ff_gust" mps="3.7"/>
<humidity value="80.5" unit="percent"/>
<pressure id="pr" unit="hPa" value="1016.0"/>
<cloudiness id="NN" percent="51.6"/>
<fog id="FOG" percent="-0.0"/>
<lowClouds id="LOW" percent="51.2"/>
<mediumClouds id="MEDIUM" percent="0.0"/>
<highClouds id="HIGH" percent="0.8"/>
<dewpointTemperature id="TD" unit="celsius" value="8.8"/>
</location>
Whole XML shown
^내가 쉽게 값을 가진 모든 이름을 표시 할 수 있지만 난 정말 그것을 제어하는 방법을 알아낼 수 없습니다. (I는 입력 (15)이 다음 시간 점검이 "T15"을지면) 가
String timeCheck = "T"+timeUserInput;
다음 I 확인 어떤 값, 예를 들면,이 입력을 획득하는 경우 : 이란 지금있는 것은 같은 사용자 입력을 저장 문자열이며 에 대한 루프 안쪽이와 "T21"
if(attributeValue.toLowerCase().indexOf(timeCheck.toLowerCase()) != -1)
과 사실이라면 나는이 경우에 온도의 값을 인쇄 할 "12.0"하지만 난의 쉬운 방법을 찾을 수 없습니다 하고있어. 모든 온도 값을 인쇄 할 수 있지만 적절한 시간의 온도 값만 원합니다.
최근 Java로 시작한 내 문제를 설명하기 위해 최선을 다했습니다. 미리 감사드립니다. 뭐든 설명 할 필요가 있다면 저에게 말해주세요.
어떻게 파싱 하시겠습니까? XPath? 색소폰? DOM? JAXB? 너 어떻게 붙어 있니? 가능하다면이 질문을 개선하십시오. 내 생각 엔 JAXB를 사용하여 XML을 유효한 객체로 변환하려고하지만 실제로는 그렇지 않습니다. –
@HovercraftFullOfEels SAXParser를 사용하고 있습니다. 나는이 특정한 가치를 얻는 방법을 모르기 때문에 붙어있다. JAXB가 무엇을하는지 확인하겠습니다! – Widdin
@HovercraftFullOfEels이 같은 : http://imgur.com/PSIF3Zj – Widdin