由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - how to insert a node in existing xml
相关主题
ASP和java也不是互相排斥啊。看了下storm,大概明白了怎么做real time系统了
A design for parameter passingjsp开发请教
What do you think of XPath, XQuery, and XSLT?[ZT] choose your java xml parser
现在有些迷惑了Does JDK bundle with an XSLT transformer?
What xml editor plugin for eclipse?请问jeditorpane怎末才能显示rss or xml?
Any testNG gui exist?Post some positions from my company
请教关于java文件操作XSLT document() Function question
用java访问数据库xslt: how to replace character
相关话题的讨论汇总
话题: xml话题: insert话题: node话题: tag话题: file
进入Java版参与讨论
1 (共1页)
v*******8
发帖数: 20
1
how to insert a node into an existing xml file? - besides creating dom then
writing out to file?
the xml file is very long (several k lines), and I want to keep the comments
in original xml file. The node needs to be insert right before the end tag
of the root
thanks
g*****g
发帖数: 34805
2
If it's simple one, using string and regex to locate the position
will be enough.

then
comments
tag

【在 v*******8 的大作中提到】
: how to insert a node into an existing xml file? - besides creating dom then
: writing out to file?
: the xml file is very long (several k lines), and I want to keep the comments
: in original xml file. The node needs to be insert right before the end tag
: of the root
: thanks

S********a
发帖数: 1163
3
there are lots of ways to do it.
u can even use XSLT to do it.

then
comments
tag

【在 v*******8 的大作中提到】
: how to insert a node into an existing xml file? - besides creating dom then
: writing out to file?
: the xml file is very long (several k lines), and I want to keep the comments
: in original xml file. The node needs to be insert right before the end tag
: of the root
: thanks

v*******8
发帖数: 20
4
can you share some more info? such as website/sample - I am using java and
the goal is not to re-generate the xml from dom (with which I cannot keep
the comments and maintain the exact same format)
Actually I was thinking about goodbug's way before my original post, but it
seems so "brute force" and low tech :) so I hesitated.
thanks

【在 S********a 的大作中提到】
: there are lots of ways to do it.
: u can even use XSLT to do it.
:
: then
: comments
: tag

S********a
发帖数: 1163
5
using javax.xml.transform package, basically:
Transformer t = TransformerFactory.newTransformer(new StreamSource(xsltFile)
);
t.transform(new StreamSource(destFile), new StreamSource(sourceFile));
then u do whatever u want in xslt..

it

【在 v*******8 的大作中提到】
: can you share some more info? such as website/sample - I am using java and
: the goal is not to re-generate the xml from dom (with which I cannot keep
: the comments and maintain the exact same format)
: Actually I was thinking about goodbug's way before my original post, but it
: seems so "brute force" and low tech :) so I hesitated.
: thanks

c*****t
发帖数: 1879
6
In your case, writing your own scanner would be highest performance and
straight forward than ANY other method.
Just keep track the last line that does not have an empty line (thus
guarrantees the root tag is in this line) and dump the rest.
Then search for the (root = root tag name), and insert your
tag in front.

then
comments
tag

【在 v*******8 的大作中提到】
: how to insert a node into an existing xml file? - besides creating dom then
: writing out to file?
: the xml file is very long (several k lines), and I want to keep the comments
: in original xml file. The node needs to be insert right before the end tag
: of the root
: thanks

A**o
发帖数: 1550
7
only works if the file is well formatted.

【在 c*****t 的大作中提到】
: In your case, writing your own scanner would be highest performance and
: straight forward than ANY other method.
: Just keep track the last line that does not have an empty line (thus
: guarrantees the root tag is in this line) and dump the rest.
: Then search for the (root = root tag name), and insert your
: tag in front.
:
: then
: comments
: tag

c*****t
发帖数: 1879
8
No need to. At most just track
【在 A**o 的大作中提到】
: only works if the file is well formatted.
t*******e
发帖数: 684
9
办法太多了,任何XML process的runtime都能干的。
1 (共1页)
进入Java版参与讨论
相关主题
xslt: how to replace characterWhat xml editor plugin for eclipse?
佛渡有缘人 - J2EE Developer(最大期权,期货结算公司), 站内Any testNG gui exist?
J2EE Developer(最大期权,期货结算公司), 站内,需绿卡请教关于java文件操作
我自己编了个Java面试题用java访问数据库
ASP和java也不是互相排斥啊。看了下storm,大概明白了怎么做real time系统了
A design for parameter passingjsp开发请教
What do you think of XPath, XQuery, and XSLT?[ZT] choose your java xml parser
现在有些迷惑了Does JDK bundle with an XSLT transformer?
相关话题的讨论汇总
话题: xml话题: insert话题: node话题: tag话题: file