jdom

XML file is not updating using the jdom

早过忘川 提交于 2019-12-01 08:35:01
following is my java code for reading a xml file and updating some values in it. public static void writeLexicon(String word, String tag) { int newFreq=0; int tagAvailability = 0; int wordAvaialbility = 0; try { if (new File("./src/Lexicon.xml").exists()) { Document readDoc = getXMLFile(); Element root = readDoc.getRootElement(); for (Element curElem : root.getChildren("lexiconElement")) { if (word.equals(curElem.getChildText("word"))) { // word avaialble List<Element> subEle = curElem.getChildren(); for (int i = 1; i < subEle.size(); i++) { if (tag.equals(subEle.get(i).getChildText("tag"))) {

XML file is not updating using the jdom

我与影子孤独终老i 提交于 2019-12-01 05:54:42
问题 following is my java code for reading a xml file and updating some values in it. public static void writeLexicon(String word, String tag) { int newFreq=0; int tagAvailability = 0; int wordAvaialbility = 0; try { if (new File("./src/Lexicon.xml").exists()) { Document readDoc = getXMLFile(); Element root = readDoc.getRootElement(); for (Element curElem : root.getChildren("lexiconElement")) { if (word.equals(curElem.getChildText("word"))) { // word avaialble List<Element> subEle = curElem

create xml with jdom, how to set standalone=“no” attribute

廉价感情. 提交于 2019-12-01 04:12:33
问题 When I create a jdom document (Document doc = new Document();), by default I only see version and encoding in the xml header: <?xml version="1.0" encoding="utf-8" ?> How can I add the standalone attribute to get: <?xml version="1.0" encoding="utf-8" standalone="no" ?> 回答1: The Header is normally stripped by the XMLParser before the document gets to JDOM. I'm pretty sure you mean you're looking at the output from JDOM, which adds the XML declaration back in. You can adjust how the XML

What is best way to change one value in XML files in Java?

佐手、 提交于 2019-12-01 02:56:39
I have an XML file and I know the node name I need to change the value for. The nodename is ipAddress. I can use JDOM, get document, get node and change the value and write it or I can write an XSLT file. The code changing value goes from Java, so my question is which option is better? The size of the XML file can be different. Another XSLT-related question: Is it possible to write an XSLT file such that I will not be listing all nodes that are in XML but will just specify like if node == ipAddress , then take the new value, and how would I apply the XSLT transformation from Java? Thank you.

What is best way to change one value in XML files in Java?

末鹿安然 提交于 2019-11-30 23:40:13
问题 I have an XML file and I know the node name I need to change the value for. The nodename is ipAddress. I can use JDOM, get document, get node and change the value and write it or I can write an XSLT file. The code changing value goes from Java, so my question is which option is better? The size of the XML file can be different. Another XSLT-related question: Is it possible to write an XSLT file such that I will not be listing all nodes that are in XML but will just specify like if node ==

How to get node contents from JDOM

一笑奈何 提交于 2019-11-30 04:25:54
I'm writing an application in java using import org.jdom.*; My XML is valid,but sometimes it contains HTML tags. For example, something like this: <program-title>Anatomy & Physiology</program-title> <overview> <content> For more info click <a href="page.html">here</a> <p>Learn more about the human body. Choose from a variety of Physiology (A&P) designed for complementary therapies.&#160; Online studies options are available.</p> </content> </overview> <key-information> <category>Health & Human Services</category> So my problem is with the < p > tags inside the overview.content node. I was

Performing complicated XPath queries in Scala

北战南征 提交于 2019-11-30 02:10:25
问题 What's the simplest API to use in scala to perform the following XPath queries on a document? //s:Annotation[@type='attitude']/s:Content/s:Parameter[@role='type' and not(text())] //s:Annotation[s:Content/s:Parameter[@role='id' and not(text())]]/@type ( s is defined as a nickname for a particular namespace) The only documentation I can find on Scala's XML libraries has no information on performing complicated real XPath queries. I used to like JDOM for this purpose (in Java), but since JDOM

How to convert org.jdom.Document to String

回眸只為那壹抹淺笑 提交于 2019-11-30 00:57:55
问题 How do I to convert an org.jdom.Document to a String in Java? 回答1: new XMLOutputter().outputString(doc); 回答2: I got the answer myself XMLOutputter xmOut = new XMLOutputter(); System.out.println("----" + xmOut.outputString(doc)); 来源: https://stackoverflow.com/questions/4343683/how-to-convert-org-jdom-document-to-string

Parsing malformed/incomplete/invalid XML files [duplicate]

只愿长相守 提交于 2019-11-29 10:37:29
This question already has an answer here: How to parse invalid (bad / not well-formed) XML? 4 answers I have a process that parses an XML file using JDOM and xpath to parse the file as shown below: private static SAXBuilder builder = null; private static Document doc = null; private static XPath xpathInstance = null; builder = new SAXBuilder(); Text list = null; try { doc = builder.build(new StringReader(xmldocument)); } catch (JDOMException e) { throw new Exception(e); } try { xpathInstance = XPath.newInstance("//book[author='Neal Stephenson']/title/text()"); list = (Text) xpathInstance

xml的2种解析方式(DOM和SAX解析方式)

纵然是瞬间 提交于 2019-11-29 06:03:57
1、xml的解析的简介(*****) * dom和sax区别 ==================================================================== 1、xml的解析的简介(写到java代码)(***今天最重要的内容*****) * xml是标记型文档 * js使用dom解析标记型文档? - 根据html的层级结构,在内存中分配一个树形结构,把html的标签,属性和文本都封装成对象 - document对象、element对象、属性对象、文本对象、Node节点对象 * xml的解析方式(技术):dom 和 sax ** 画图分析使用dom和sax解析xml过程 *** dom解析和sax解析区别: ** dom方式解析 - 根据xml的层级结构在内存中分配一个树形结构,把xml的标签,属性和文本都封装成对象 * 优点:很方便实现增删改操作 * 缺点:如果文件过大,造成内存溢出 ** sax方式解析 - 采用事件驱动,边读边解析,从上到下,一行一行的解析,解析到某一个对象,返回对象名称, 当SAX解析结束,不会保存任何XML文档的数据。 * 优点:如果文件过大,不会造成内存溢出,方便实现查询操作 * 缺点:不能实现增删改操作 * 想要解析xml,首先需要的解析器 ** 不同的公司和组织提供了 针对dom和sax方式的解析器