문제

브라우저가 DOM 접근 방식으로 XML을 지원한다는 것을 알고 있습니다.

GWT를 사용하는 응용 프로그램이 있으며 서버에서 파일을 업로드하는 응용 프로그램이 있습니다. 업로드가 완료되면 파일 업로드이므로 서버가 Bean으로 클라이언트에 다시 응답해야합니다. 이는 파일 업로드이므로 응답은 서블릿에서 처리됩니다.

서블릿에서 생성 한 출력을 읽어 클라이언트에서 문자열을 읽을 수 있습니다. 콩을 클라이언트의 물체로 다시 변환 할 XML 같은 구조로 변환 할 계획입니다.

그렇다면 내 클라이언트 가이 응답을 XML로 취급하고 반복 할 수 있습니까?

도움이 되었습니까?

해결책

자세히보기 http://gwt.components.googlepages.com/simplexmlparser

private void parseMessage(String messageXml) {
  try {
    // parse the XML document into a DOM
    Document messageDom = XMLParser.parse(messageXml);

    // find the sender's display name in an attribute of the <from> tag
    Node fromNode = messageDom.getElementsByTagName("from").item(0);
    String from = ((Element)fromNode).getAttribute("displayName"); 
    fromLabel.setText(from);

    // get the subject using Node's getNodeValue() function
    String subject = messageDom.getElementsByTagName("subject").item(0).getFirstChild().getNodeValue();
    subjectLabel.setText(subject);

    // get the message body by explicitly casting to a Text node
    Text bodyNode = (Text)messageDom.getElementsByTagName("body").item(0).getFirstChild();
    String body = bodyNode.getData();
    bodyLabel.setText(body);    

  } catch (DOMException e) {
    Window.alert("Could not parse XML document.");
  }
}

다른 팁

jQuery를 사용하여 XML을 구문 분석 할 수 있으며 GWT에서 JSNI로 jQuery 호출을 쉽게 포장 할 수 있습니다. 여기에 입증 된 바와 같이 훨씬 덜 장점 http://marcgrabanski.com/article/jquery-makes-parsing-xml-easy

편집 : gwtquery도 그렇게 할 수 있습니까? 직선 포트가 아니기 때문에 확실하지 않습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top