1问题:
    Client 接受到服务器发过来的XML数据(以字符串形式发过来)如下.现在我要如何来解析XML里面的数据 ID,type,time,...等等
     <?xml version="1.0" encoding="GB2312"?>
    <?xml:stylesheet type="text/xsl" href="event.xsl"?>
   <data version="1.0.0 build 100" >
<event><id>21</id><type>1</type><time>2008/05/04 18:47:37 Sunday </time><param1>User</param1><param2>query process list</param2><param3>successful</param3></event>
<event><id>24</id><type>1</type><time>2008/05/04 18:47:48 Sunday </time><param1>User</param1><param2>query process list</param2><param3>successful</param3></event><event>
   2 .问题
    我想改变Jtable 一行的背景色如何来做.
    数据列数据有0,1两种情况
     0
    1
    当为1时行背景色为红

解决方案 »

  1.   

    1.将给字符串写进.xml文件 然后再解析 可以JDOM dom4j==
    2.利用CSS来控制上述.xml
      

  2.   

    参考http://www.7880.com/Info/Article-85c54ce0.html
      

  3.   

    Java标准的读写XML有两种方式 SAX 和 DOM ,对于这样的小数据用DOM就够了,自己看看JDK的帮助就可以用地
      

  4.   

    1.xml 有解析工具.
    2.改变表格的背景颜色可以通过样式设置,不同的值显示不同的样式.
      

  5.   

    如果接收的XML格式确定,可以直接用indexOf()和subString()组合得到值,再用HashTable存起来实在不行,写入到一个临时文件吧,再用SAX或DOM解析,不过性能会有点影响
      

  6.   

    用dom4j解吸XML吧,这个比较简单
      

  7.   

    你可以用dom4j去解析他的,,然后把解析的,,这个很多呀,,到网上搜索一下,,就可以了,,
      

  8.   

    我以前做的个例子,,供参考
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;import org.dom4j.*;
    import org.dom4j.io.SAXReader;public class CompanyVisitor {
    public static void main(String[] args) {

    SAXReader saxreader=new SAXReader();
    try {
    Document doc=saxreader.read(new File("company.xml"));
    doc.accept(new myVisitor());
    List list=myVisitor.getList();
    System.out.println(list.size());
    for(int i=0;i<list.size();i++){
    System.out.println(list.get(i));
    }
    } catch (DocumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }


    private static class myVisitor extends VisitorSupport{
          static  List list=new ArrayList();
          

    public static List getList() {
    return list;
    } public static void setList(List list) {
    myVisitor.list = list;
    } public void visit(Attribute node) {
    System.out.println("Attribute :"+node.getName()+"="+node.getValue());
    list.add(node.getName()+"="+node.getValue());
    } @Override
    public void visit(Element node) {
    if(node.isTextOnly()){
    System.out.println("Element :"+node.getName()+" "+node.getStringValue());
    list.add(node.getName()+" "+node.getStringValue());
    }
    else{
    System.out.println("------------"+node.getName()+"----------");
    list.add(node.getName());
    }
    } @Override
    public void visit(ProcessingInstruction node) {
    System.out.println("PI :"+node.getTarget()+" "+node.getText());

    }


    }}
      

  9.   

    2 .问题 
        我想改变Jtable 一行的背景色如何来做. 
        数据列数据有0,1两种情况 
         0 
        1 
        当为1时行背景色为红
    这个问题就更简单了,,
    最基础的了
    (x==y)?x:y
    这个你总知道把
    还可以这样的,,,
    <% if (变量==0) {%>
    <tr class=" 这里你可以通过css设置你要的背景色">
    <%}
      else if(变量==1) %>
    <tr class=" 这里你可以通过css设置你要的背景色">
    <% }%>
      

  10.   

    /**
     * 
     */
    package jdom;import java.io.FileWriter;
    import java.io.IOException;
    import java.util.List;import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.Format;
    import org.jdom.output.XMLOutputter;/**
     * @author 汪文君<a href="mailto:[email protected]">WenJun.Wang</a><br>
     * @date 2008-5-5 下午08:18:32<br>
     */
    public class CreateXML { /**
     * @param argsCreateXML.java
     */
    Element root = new Element("conf");
    Document document = new Document(root);
    public CreateXML(){
    String element1 = "readType";
    String element2 = "mainconf";
    String children = "net";
    String[] childrenElement = {"id","ip","port","type","username","password"};
    String[] childrenValue = {"k11","192.168.55.38","8025","0","maxw","maxw"};

    createFisrt(element1);
    Element element = new Element(element2);
    for(int i=0;i<2;i++){
    createMain(element,children, childrenElement,childrenValue);
    }
    addToRoot(element);
    try {
    outPutXml(document, "nms3.5.xml");
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    public  void createFisrt(String str){
    Element typeElement = new Element(str);
    typeElement.addContent("0");
    addToRoot(typeElement);
    }

    public void createMain(Element element,String str,String[] array1,String[] array2){

    Element elementChildern = new Element(str);
    element.addContent(elementChildern);
    for(int i=0;i<array1.length;i++){
    Element elementnet = new Element(array1[i]);
    elementnet.addContent(array2[i]);
    elementChildern.addContent(elementnet);

    }
    /**
     * for(String str : array){
     * element.addContent(str);
     * }
     * */

    }

    public void outPutXml(Document document,String fileName) throws IOException{
    XMLOutputter xmlout = new XMLOutputter();

    Format format = xmlout.getFormat();
    format.setEncoding("big5");
    format.setLineSeparator("\n");
    FileWriter fw = new FileWriter(fileName);
    xmlout.output(document, fw);

    }

    public void addToRoot(Element element){
    root.addContent(element);
    }

    public static void main(String[] args) {

    CreateXML createXML = new CreateXML();
    createXML.readXML();
    }

    /**
     * 读出生成的xml文件
     * */

    public void readXML(){
    SAXBuilder saxBuilder = new SAXBuilder();
    try {
    Document document = saxBuilder.build("nms3.5.xml");
    Element root = document.getRootElement();
    String readtype=root.getChildText("readType");
    System.out.println("readtype:"+readtype);
    Element mainType = root.getChild("mainconf");
    List secondChildren = mainType.getChildren("net");
    System.out.println("-------");
    for(int i=0;i<secondChildren.size();i++){
    Element net =(Element)secondChildren.get(i);
    String id = net.getChildText("id");
    String ip = net.getChildText("ip");
    String port = net.getChildText("port");
    String type=net.getChildText("type");
    String username = net.getChildText("username");
    String password = net.getChildText("password");
    System.out.println(id);
    System.out.println(ip);
    System.out.println(port);
    System.out.println(type);
    System.out.println(username);
    System.out.println(password);
    System.out.println("------");
    }
    } catch (JDOMException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }}
      

  11.   

    1.将给字符串写进.xml文件 然后再解析 可以JDOM dom4j==
    2.利用CSS来控制上述.xml