I want to extract a list of feed information from an OPML file in java. I know I have to use some xml-parse technique, but I have no idea what to use.
I am a java beginner, so could you tell me how to do it and give me an example?
Thanks a lot!!
This should fairly straight forward. You can take one of hte following two approaches.
Use java parsing capabilities and parse it as any XML file. Here is an example using DOM parse.
There are lot of the open source code/libraries for doing this. Here is one such example. This class has a method public ArrayList<OpmlElement> readDocument(Reader reader). You can create a Reader object from the OPML file and pass the same to this function. Please note that this library depends on xml Pull parser libraries. So if you do not want to add another dependency use the first approach.
Here is another example on this forum itself.
Related
We have a graph datastructure for our little 3D program which just contains info about vertices and edges, no fill etc. We just want to get the information about the point locations and how they are connected together. (From what I understand, this is called Mesh data, is that correct terminology?)
Is there a library that would do something like this, or go anywhere near what I want to achieve? Is there, for example, a library which will allow me to just use a function which takes in that file and instantiate a new object that will have all this mesh info?
If not, what would be the steps to get this done?
I understand you need to parse the 3D-information in COLLADA and convert it to your internal data structure. You can create POJOs for COLLADA elements using JAXB and COLLADA schema file. But it is not really easy because there are some name collision problems in the schema. You need to do some hacks to get rid of this. Here is a link which explains how to do that:
http://shinoblogbyshiva.blogspot.de/2009/01/compiling-collada-15-schema-by-jaxb.html.
According to this link, you need to have 3 things:
1) Collada XML-Schema
2) A schemalet for help (http://interreality.org/bzroot/vos/supervos/colladajaxb/src/simpleMode.xsd)
3) And the latest version of JAXB.
Then use xjc from JAXB like this:
"xjc collada_schema_1_5.xsd -extension simpleMode.xml"
Be sure the paths of the files are correct.
After you have your POJOs, you can parse the COLLADA file. But for the conversion process, you are alone. You should understand the definition of elements in COLLADA and compare them with your own structure. It is a little bit complicated, I can recommend you to read the book "Collada: Sailing the Gulf of 3d Digital Content Creation" from Remi Arnaud.
If you can, switch to wavefront .obj - Files. These can be parsed in a few lines and are likely the thing you want (just import your collada to blender for example and export as obj again)
If you cant, you could give lwjgl a try. This library gives you access to assimp, which can load any 3d-object-format for you
I am attempting to parse a KML file which has some non-standard tags:
<Placemark id="plot">
<Type1> Type 1 </Type1>
<SA>62</SA>
<Type2> Type 2 </Type2>
I'm attempting to read/parse the file, obtain the representative elements as described above and then all the coordinates, and finally write the output to a text file for downstream use. I'm able to parse the file and get the coordinates with no issues but have been unable to determine a way to get the custom elements, and I need the data to format the output file correctly. The elements are not wrapped in an extendeddata structure or any other grouping.
I am hoping someone has run into this before and can offer some guidance on the best way to read the data via supplied methods for javaapiforkml.
You can have a look at OSMBonusPack KML parser, mainly here.
It's open source, so you can pick the classes you need, remove all Android-specific features, and add handling for your custom tags.
We have a new requirement:
There are some BIG xml files keep coming into our system and we will need to process them immediately and quickly using Java. The file is huge but the required information for our processing is inside a element which is very small.
...
...
What is the best way to extract this small portion of the data from the huge file before we start processing. If we try to load the entire file, we will get out of memory error immediately due to size. What is the efficient way in Java that I can use to get the ..data..data..data.. data element without loading or reading the file line by line. Is there any SAX Parser that I can use to get this done?
Thank you
The SAX parsers are event based and are much faster because they do what you need: they don't read the xml document entirely. There is a SAXParser available in the Java distributions.
I had to parse huge files in a previous project (1G-2G) and didn't want to deal with using SAX. I find SAX too low-level in some instances and like keepings a traversal approach in most cases.
I have used the VTD library http://vtd-xml.sourceforge.net/. It's an EXTREMELY fast library that uses pointers to navigate through the document.
Well, if you want to read a part of a file, you will need to read each line of the file to be able to identify the part of the file of interest and then extract what you need.
If you only need a small portion of the incoming XML, you can either use SAX, or if you need to read only specific elements or attributes, you could use XPath, which would be a lot simpler to implement.
Java comes with a built-in SAXParser implementation as well as an XPath implementation. Find the javadocs for SAXParser here and for XPath here.
StAX is another option based on steaming the data, like SAX, but benefits from a more friendly approach (IMO) to processing the data by "pulling" what you want rather than having it "pushed" to you.
Is there a Json - parser for java online that can help me to create Java - objects from Json-string? (I found similar one but there I can translate json-string in Java -objects only if I have url for my json-string)?
Thanks for the link, this should be easy:
upload your JSON string to a site like pastebin.com
get the RAW link, i.e. the one without the PasteBin website around)
put that into http://jsongen.byingtondesign.com
Have a look at http://jackson.codehaus.org/
But be sure that you really want to put it into Java objects, because whenever the JSON representation changes, translation will break of course.
QuickType.io is exactly what you're looking for.
For the record, I'm unaffiliated.
I need to parse a xml file using JAVA and have to create a bean out of that xml file after parsing .
I need this while using Spring JMS in which producer is producing a xml file .First I need to read the xml file and take action according .
I read some thing about parsing and come with these option
xpath
DOM
Which ll be the best option to parse the xml file.
did you check JAXB
There's three ways of parsing an XML file, SAX, DOM and StAX.
DOM will parse the whole file and build up a tree in memory - great for small files but obviously if this is huge then you don't want the entire tree just sitting in memory! SAX is event based - it doesn't load anything into memory per-se but just fires off a series of events as it reads through the file. StAX is a median between the two, the application moves the cursor forward as it needs, grabbing the data as it goes (so no event firing or huge memory consumption.)
What one you use will really depend on your application - all have built in libraries since Java 6.
Looks like, you receive a serialized object via Java messaging. Have a look first, how the object is being serialized. Usually this is done with a library (jaxb, axis, ...) and you could use the very same library to create a deserializer.
You will need:
The xml schema (a xsd file)
The Java bean class (very helpful, it should exist)
Then, usually the library will create all helper classes and files and you don't have to care about parsing.
if you need to create an object, just extract the needed properties and go on...
I recommend using StaX, see this tutorial for more information.
Umh..there are several ways you can parse an xml document to into memory and work with it. You mentioned DOM. DOM actually holds uploads the whole document into memory and then allows you to move between different branches of the XML document.
On the other hand, you could use StAX. It works similar to DOM. The only difference is that, it streams the content of the XML document thus allowing better allocation of memory. On the other hand, it does not retain the information that has already been read.
Look at : http://download.oracle.com/javaee/5/tutorial/doc/bnbem.html It gives details about both parsing methods and example code. Hope that helps.