使用JDOM创建具有嵌套元素的XML文件(Creating XML file with nested elements using JDOM)
我使用JDOM创建了一个XML文件(来自Object)并且它可以工作,但我无法让一个嵌套元素(教师)正常工作。
以下是创建文件的方法:
public void writeFileUsingJDOM(List<Activity> activityList, String fileName) throws IOException { Document doc = new Document(); doc.setRootElement(new Element("Activities", Namespace.getNamespace("http://www.jana.com/activities"))); for(Activity act : activityList) { Element activity = new Element("Activity"); activity.setAttribute("id", act.getActivityId().toString()); activity.addContent(new Element("ActivityDescription").setText(act.getActivityDescription())); activity.addContent(new Element("CourseDescription").setText(act.getCourse().getCourseDescription())); // retrieve the list of teachers based on activity id List<Teacher> teacherList = teacherService.getAll(act.getActivityId()); activity.addContent(new Element("Teachers")); // THIS IS WRONG! for(Teacher teach : teacherList) { activity.addContent(new Element("Teacher").addContent(new Element("Name").setText(teach.getFirstName() + " " + teach.getLastName()))); } activity.addContent(new Element("SubmissionDate").setText(act.getSubmissionDate())); activity.addContent(new Element("Score").setText(act.getScore().toString())); activity.addContent(new Element("Note").setText(act.getNote())); doc.getRootElement().addContent(activity); } //write JDOM document to file XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); xmlOutputter.output(doc, new FileOutputStream(fileName)); }
我在我创建的XML文件中得到了这个:
<?xml version="1.0" encoding="UTF-8"?> ... <Activity xmlns="" id="82"> <ActivityDescription>Some other activity</ActivityDescription> <CourseDescription>Some other course</CourseDescription> <Teachers /> <!-- THIS IS THE PROBLEM! Teacher elements should be inside Teachers element --> <Teacher> <Name>Douglas Richardson</Name> </Teacher> <Teacher> <Name>Kieran Pittman</Name> </Teacher> <SubmissionDate>01/21/2014</SubmissionDate> <Score>30</Score> <Note>Some other note</Note> </Activity> ... </Activities>
它看起来应该是这样的:
<Teachers> <Teacher> <Name>Douglas Richardson</Name> </Teacher> <Teacher> <Name>Kieran Pittman</Name> </Teacher> </Teachers>
任何人都可以告诉我如何实现这一目标? 谢谢...
I created an XML file (from Object) using JDOM and it works, but I can't get one nested element (Teachers) to work properly.
Here is the method that creates the file:
public void writeFileUsingJDOM(List<Activity> activityList, String fileName) throws IOException { Document doc = new Document(); doc.setRootElement(new Element("Activities", Namespace.getNamespace("http://www.jana.com/activities"))); for(Activity act : activityList) { Element activity = new Element("Activity"); activity.setAttribute("id", act.getActivityId().toString()); activity.addContent(new Element("ActivityDescription").setText(act.getActivityDescription())); activity.addContent(new Element("CourseDescription").setText(act.getCourse().getCourseDescription())); // retrieve the list of teachers based on activity id List<Teacher> teacherList = teacherService.getAll(act.getActivityId()); activity.addContent(new Element("Teachers")); // THIS IS WRONG! for(Teacher teach : teacherList) { activity.addContent(new Element("Teacher").addContent(new Element("Name").setText(teach.getFirstName() + " " + teach.getLastName()))); } activity.addContent(new Element("SubmissionDate").setText(act.getSubmissionDate())); activity.addContent(new Element("Score").setText(act.getScore().toString())); activity.addContent(new Element("Note").setText(act.getNote())); doc.getRootElement().addContent(activity); } //write JDOM document to file XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); xmlOutputter.output(doc, new FileOutputStream(fileName)); }
I get this in my created XML file:
<?xml version="1.0" encoding="UTF-8"?> ... <Activity xmlns="" id="82"> <ActivityDescription>Some other activity</ActivityDescription> <CourseDescription>Some other course</CourseDescription> <Teachers /> <!-- THIS IS THE PROBLEM! Teacher elements should be inside Teachers element --> <Teacher> <Name>Douglas Richardson</Name> </Teacher> <Teacher> <Name>Kieran Pittman</Name> </Teacher> <SubmissionDate>01/21/2014</SubmissionDate> <Score>30</Score> <Note>Some other note</Note> </Activity> ... </Activities>
And it should look like this:
<Teachers> <Teacher> <Name>Douglas Richardson</Name> </Teacher> <Teacher> <Name>Kieran Pittman</Name> </Teacher> </Teachers>
Can anyone please tell me how to achieve this? Thank you...
原文:https://stackoverflow.com/questions/21317469
最满意答案
现在转到您的旧克隆,然后推送它:
$ cd old.ga $ gitolite push -f ...usual git progress output deleted... remote: FATAL: git config foo.bar not allowed remote: check GIT_CONFIG_KEYS in the rc file To /home/git/repositories/gitolite-admin.git + 7eb8163...1474770 master -> master (forced update)
AAHA! 我忘了在新的rc文件中设置
GIT_CONFIG_KEYS
(GIT_CONFIG_KEYS
新名称),所以修复:$ vim ~/.gitolite.rc (edit and set it to `.*` for now)
确保你的
.gitolite.rc
确实包含:GIT_CONFIG_KEYS => '.*',
(在这个GitLab问题中也提到过,即使它不是问题的直接根本原因)
我有另一个问题是我的
projects.list
文件在我向gitolite-admin
conf添加新的存储库时没有自动更新。
对于gitweb,我不得不手动编辑该文件。 你知道可能导致什么吗?“ 与外部工具接口 ”页面提到:
gitweb可读repos列表被写入一个文件,其名称由
rc
文件变量GITWEB_PROJECTS_LIST
。
如果未指定或为空,则此变量的默认值为$HOME/projects.list
。确保你的
.gitolite.rc
:GITWEB_PROJECTS_LIST => '/path/to/projects.list',
The Gitolite g2-g3 migration page mentions:
Now go to your old clone, and push it:
$ cd old.ga $ gitolite push -f ...usual git progress output deleted... remote: FATAL: git config foo.bar not allowed remote: check GIT_CONFIG_KEYS in the rc file To /home/git/repositories/gitolite-admin.git + 7eb8163...1474770 master -> master (forced update)
Aaha! I forgot to set
GIT_CONFIG_KEYS
(new name forGL_GITCONFIG_KEYS
) in the new rc file so fix that:$ vim ~/.gitolite.rc (edit and set it to `.*` for now)
Make sure your
.gitolite.rc
does contain:GIT_CONFIG_KEYS => '.*',
(It was also mentioned in this GitLab issue, even though it wasn't the direct root cause of the issue)
I got another issue which is my
projects.list
file does not get updated automatically when I added a new repository togitolite-admin
conf.
For gitweb, I had to manually edited that file. Did you know what could possibly cause that?The "interfacing with external tools" page mentions:
The list of gitweb-readable repos is written to a file whose name is given by the
rc
file variableGITWEB_PROJECTS_LIST
.
The default value of this variable, if it is not specified or empty, is$HOME/projects.list
.Make sure you have in your
.gitolite.rc
:GITWEB_PROJECTS_LIST => '/path/to/projects.list',
相关问答
更多-
您没有在自述文件中看到“ git@xxx:/home/git/repositories/foo.git ”网址。 你看到的是: git@xxx:foo 换句话说,您不能指定完整路径。 另外,请确保不要删除本地repo gitolite-admin 。 如果你有一个新的repo foo ,你必须在其他地方克隆它: git clone git@xxx:foo 我怀疑你只有一个ssh公钥/私钥,但如果你必须维护多个身份,请参阅“ 一台机器上的多个gitolite用户 ”。 You don't see "git ...
-
新密钥在什么时候被添加到.ssh授权密钥文件中? 推送后,立即提供您的密钥: 是一个公钥(一行类似于ssh-rsa AAAAB3NzaC1yc2EAA...hFvETUVDvF2iZ ) 是访问gitolite: tom.pub的资源名称后面的名称 正如OP Dee 在评论中确认的那样 ,问题在于代表用户的公钥文件名: 唯一的错误是错误的用户名,我认为这是因为我在一组用户的名字中使用了' / ' 实际上, 用户名模式是: ^\@?[0-9a-zA-Z][-0-9a-zA-Z._\@+]*$ 不允许' / ...
-
gitolite用户无法连接(gitolite users cannot connect)[2023-07-15]
在你的机器上执行ssh -vvvv git@gitserver.com 。 你会看到提供什么密钥。 现在在这个用户的机器上做同样的事情。 另外请将你的配置文件发布到gitolite上,如果你有它们,那么〜/ .ssh / config文件,如果你们有它们的话。 用一般的东西替换你的敏感回购。 (upvoted你的问题) do a ssh -vvvv git@gitserver.com on your machine. You will see what keys are offered. Now do th ... -
我可以添加本地用户来使用SSH管理Gitolite存储库吗?(Can I Add Local Users to Manage a Gitolite Repository with SSH?)[2022-11-28]
URL正面的gitolite @实际上并不是您使用SSH时的用户。 它是服务器上的服务(我假设)所以gitolite @ localhost:my-repo完全有效。 在使用GIT时,您将始终看到对git @的引用。 您的服务是gitolite,因此将始终使用gitolite @。 Git服务器使用SSH公钥进行身份验证,因此您创建的密钥允许用户连接到服务器。 该密钥也与该用户有关,因此当使用该密钥时,假设用户发出诸如提交之类的git命令。 从侧面说明,当我第一次使用我们的GIT系统时,一位同事推荐http ... -
无法添加Gitolite用户(Can not add user with Gitolite)[2022-07-07]
使用gitolite ,所有ssh通信都使用用于安装gitolite的帐户完成。 在你的情况下: gitolite 。 但是,您可以指定不同的公钥,以指示gitolite对其他用户进行身份验证。 ssh会话仍将以gitolite形式执行。 但传递给gitolite脚本的名称将被testid (因为公钥在gitolite中以~/.ssh/authorized_keys为' testid ') 所以使用~testid/.ssh/config文件,在其中提到正确的参数: Host gitolitesrv Host ... -
git clone myname@myserver:/home/git/repositories/testing.git 完全绕过没有被称为的gitolite 使用错误的帐户'myname',该帐户无权阅读git帐户文件夹。 应该做的是: git clone git@myserver:test_repo.git or git clone git@myserver/test_repo.git 你不应该指定'repositories'文件夹(gitolite知道repo应该在哪里) 假设ssh -Tv ...
-
Gitolite g2-g3迁移页面提到: 现在转到您的旧克隆,然后推送它: $ cd old.ga $ gitolite push -f ...usual git progress output deleted... remote: FATAL: git config foo.bar not allowed remote: check GIT_CONFIG_KEYS in the rc file To /home/git/repositories/gitolite-admin.git + 7eb ...
-
我通过阅读desc命令的代码找到了所遗漏的内容(在doc中没有看到) git@host $ nano ~/.gitolite.rc %RC = ( [...] WRITER_CAN_UPDATE_DESC => 1, [...] ) I found what was missing by reading the code of the desc command (didn't see it in the doc) git@host $ nano ~/.gitoli ...
-
如何在Gitolite配置中为存储库添加描述(How to add description for a repository in Gitolite configuration)[2023-05-04]
我很高兴现在说它是固定的。 我在gitolite post_compile部分添加了这个https://github.com/sitaramc/gitolite/blob/master/src/triggers/post-compile/update-description-file脚本。 1.打开HOME目录中的.gitolite.rc文件并编辑post_compile部分。 POST_COMPILE => [ 'post-compile/ss ... -
我实际上不需要gitweb规则或project.list在我的gitweb设置中完成: 我只确保我有一个gitweb.conf.pl : 将由gitweb调用(通过gitweb_config.perl文件,如果gitweb检测到它存在,则调用该文件) 将调用gitolite来查看是否可以授予或应该拒绝访问回购。 I don't actually need gitweb rules or project.list to be complete in my gitweb setup: I only make s ...