Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » how to process XML code in Eclipse
how to process XML code in Eclipse [message #276399] Tue, 23 November 2004 00:16 Go to next message
Eclipse UserFriend
Originally posted by: tanut.sanuk.biz

I decide to use XML for saving my plugin option. So how to getting start
using XML in Eclipse?

Thanks
Re: how to process XML code in Eclipse [message #276407 is a reply to message #276399] Tue, 23 November 2004 05:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: leo.nowhere.com

Tanut Apiwong wrote:

> I decide to use XML for saving my plugin option. So how to getting start
> using XML in Eclipse?

> Thanks

Don't know if this helps. It's code-snipplet for reading XML:

SAXReader reader = new SAXReader();
Document doc = null;
try {
doc = reader.read(ColoringEditorTools.getFile(filename));
} catch (DocumentException e) {
e.printStackTrace();
return;
} catch(IOException ioe) {
ioe.printStackTrace();
}
Element root = doc.getRootElement();
//List properties = root.elements("PROPS");

and for further infos see:

http://www.dom4j.org/guide.html
Re: how to process XML code in Eclipse [message #276409 is a reply to message #276407] Tue, 23 November 2004 06:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tanut.sanuk.biz

Thanks you. but Is Eclipse has build-in XML Parser?
as I see many Eclipse configuration file in form of XML

Tanut Apiwong
Re: how to process XML code in Eclipse [message #276415 is a reply to message #276409] Tue, 23 November 2004 09:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi Tanut,

you need nothing special from Eclipse. JDK 1.4 has included XML Parsers and
XPATH-API.

Look at the following classes

import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;
import org.w3c.dom.Document;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.traversal.NodeIterator;


the following snippet converts a String into a "DOM" Document, which is much
easier to work with than SAX.
With the XPATH-Expressions you can select Nodes.

// wrap the string as InputSource
InputSource in = new InputSource(new StringReader(strXML));

// standard for getting the factory
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();

// parse the input
Document doc = dfactory.newDocumentBuilder().parse(in);

// select an XPATH expression (e.g. for <example><data
id="1">text1</data><data id="2">text2</data></examples)
NodeIterator ni = XPathAPI.selectNodeIterator(doc, "/example/data/text()");
// to select attributes you need "@": /examples/data/@id
// also you can add conditions: "/examples/data[@id=2]/text() --> text2

// get the first result
Node n = ni.nextNode();

// get the value (text1)
String result = n.getNodeValue();

Best regards,
feri
Re: how to process XML code in Eclipse [message #276469 is a reply to message #276415] Tue, 23 November 2004 22:22 Go to previous message
Eclipse UserFriend
Originally posted by: tanut.sanuk.biz

Thanks you very much.
Your snippet is very useful.

Tanut Apiwong
Previous Topic:Displaying build output in a view
Next Topic:How to add log to the eclipse error log? please advice
Goto Forum:
  


Current Time: Sat May 31 06:21:49 EDT 2025

Powered by FUDForum. Page generated in 0.02593 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top