How to feed a Model with a DOM tree - jena

The XML data to be used with the Model is available as an org.w3c.dom.Element, due to unmarshalling an XML wrapper containing up to 100 individual rdf:RDF nodes.
Currently I'm converting the DOM tree to a string, and an InputStream fed with the String can be passed to the Model read method.
Isn't there a more direct method for feeding a Model?

There is class DOM2Model.create(...).load(...) which might work - very old code.
The main RDF/XML parsing is SAX-based and streaming, not XML-tree based.

Related

Do I have to deserialize the whole complex json file (with many nested arrays and objects) when I need only one object? Flutter, Dart

https://github.com/enter link description herePoojaB26/ParsingJSON-Flutter/blob/master/assets/page.json
That's a tiny JSON file and there is no reason for premature optimizations.
Just deserialize it and then access the items of the generated Dart data structures to get what you need. Everything else is probably equally expensive and won't buy you anything.

How to prohibit DTD entities

I'm using the XML Tree API and the XML Parser API in c++, and I would like to prohibit entities creation in my XML documents.
What is the best way to do that when using these API's?
I've only seen examples of how to prohibit DTD entities when using XML Reader, and none when using the XML Tree or Parser API.
Thanks!
When using the tree API, you can call xmlGetIntSubset and inspect the xmlDtd structure to check whether a document contains entity declarations. When using the SAX parser, you can register an entityDeclSAXFunc callback.

Ant task for generating XSD from POJOs

Is there an ant task for generating an XSD from POJOs?
I'm presuming that you want to serialize a Java POJO object and then use XSD to validate the serialised XML data, or author new object instances which can instantiated via your de-serialization process.
Thing is Java XML serialization comes in two favours (Examples follow):
Xstream XML is dynamically generated from fixed object class description
XMLBeans Java classes dynamically generated from fixed XML Schema
Now perhaps you're using something else that combines both approaches?
What I'd recommend is create (or generate) an XSD based on the XML your object creates when serialized. Relatively speaking Java objects don't change that often and when they do a far great challenge is supporting multiple versions (Reading data encoded for the older version of your object). To address this challenge I'd recommend reading the following article for one possible solution:
http://java.dzone.com/articles/migrate-serialized-java

struts2 and dojo grid

I need an example for populating the dojo grid with the data coming from server. I have struts2 and dojo application in which action class is setting a model variable of type hashmap as the result containing different values that needs to be shown in the form of grid.
Now how can i represent this hashmap in the form of grid data. can you please giving a sample example application which converts the hashmap to json and then uses this json to populate the grid.
I use Jackson to serialize to JSON. Does each item in the map represent a row in the grid? How complex is the data that you are serializing?
https://github.com/FasterXML/jackson-core
If the data structure is simple, then you can probably get away with just using Jackson.
When you want to begin serializing more complex data structures, then you might need to enhance your serialization engine.
I have written some stuff that can do this. Too much to explain here but you can check out these blog posts and see the code on git hub:
http://swingingcode.blogspot.com/2012/04/json-serialization-engine-part-i.html
http://swingingcode.blogspot.com/2012/04/json-serialization-engine-part-ii.html
https://github.com/cswing/evinceframework/tree/master/web/src/java/com/evinceframework/web/dojo/json

smartgwt beginner- how to display xml entered in text area into tree

I am working with Smart GWT 3.0 LGPL- I am trying to display in a tree the entire block of XML entered by user into a text area.
I can get the nodelist from the xml entered by user, however in Smart GWT, Tree widget accepts only TreeNode[] members as data.
How do I convert the NodeList (obtained using GWT's inbuilt XML parser) into TreeNode[]? Is my approach correct(to display the xml in tree form)? Or is the solution to solve this problem completely different from what I am thinking?
I assume you use the SmartGWT's TreeGrid object to create the tree. The TreeGrid is just a specialized ListGrid and, as the later, it can be databounded to a Datasource, which can easily parse an XML. Look at this example. It should help you to create a solution to your problem. You can just show only one field in your TreeGrid, if all you need is a simple tree.
In the case that you can't access the xml data through a URL, like accessing them through your text area, after you have parsed them as a NodeList, you should iterate them and create an array of TreeNode objects. For each Something object you should set its associated TreeNode object's attributes using the setAttribute(attributeName, attributeValue) methods. Then create a Tree object, and starting from the root you can add the TreeNode objects using the various methods of the Tree, at the required position. Then a simple: treeGrid.setData(Tree tree) will load and show your data in your TreeGrid.
You can create an array TreeNode[] which have size as nodelist's length, and in a cycle to put on a value. And after that you can set in a tree this TreeNode[].

Resources