简体   繁体   English

JAVA绑定XML以更新GUI,反之亦然

[英]JAVA binding an XML to update a GUI and vice versa

I'm using JAXB to model a schema and wrap XML data in java classes. 我正在使用JAXB对模式进行建模并将XML数据包装在java类中。 I created a GUI which represents the same schema as well. 我创建了一个GUI,它也代表相同的架构。 I want to bind the 2 together - meaning when ever the GUI is changed the XML data (Jaxb object) will reflect the changes, and when ever i read a XML file the gui will populate according to the xml nodes values. 我想将2绑定在一起-意味着无论何时更改GUI,XML数据(Jaxb对象)都将反映更改,并且每当我读取XML文件时,GUI就会根据xml节点值进行填充。 How can i connect between the 2? 我如何在两个之间连接? A pseudo code i'm trying to implement would look like: 我尝试实现的伪代码如下所示:

  • Read_XML_Procedure: Read_XML_Procedure:

Read XML file populate GUI gui.firstName = xml.firstName gui.lastName = xml.lastname ... 读取XML文件填充GUI gui.firstName = xml.firstName gui.lastName = xml.lastname ...

  • GUI side: GUI端:

gui.entry.name = "john" => xml.name = "john" gui.entry.name =“ john” => xml.name =“ john”

I don't want to have to write the parser manually because i have about 1000 different entries to populate. 我不想手动编写解析器,因为我要填充大约1000个不同的条目。 In a scripting language such as TK i know that entries can be attached to variables. 在诸如TK之类的脚本语言中,我知道条目可以附加到变量中。 when the variable is changed then the entry reflects that automatically Thanks 当变量更改时,该条目会自动反映出来,谢谢

You may want to use JAXB binder here. 您可能要在这里使用JAXB活页夹。 This will let you make changes in XML and apply it to the object model, or changes in the object model and apply it to XML. 这将使您可以更改XML并将其应用于对象模型,或者更改对象模型并将其应用于XML。

For more information: 欲获得更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM