I need help in constructing XML dynamically. I have a XSD associated with the XML. Thing is my xml contains repititive elements/block. Sometimes it might contain 3 elements or sometime only one. Sample xml is below
<?xml version="1.0" encoding="utf-8"?>
<addml>
<objectStore>
<folder>
<folderProperties>
<documentId>str1234</documentId>
<documentTitle>str1234</documentTitle>
<dateCreated>str1234</dateCreated>
</folderProperties>
<documents>
<document>
<docProperties>
<documentId>str1234</documentId>
<documentTitle>str1234</documentTitle>
<dateCreated>str1234</dateCreated>
</docProperties>
</document>
<document>
<docProperties>
<documentId>str1234</documentId>
<documentTitle>str1234</documentTitle>
<dateCreated>str1234</dateCreated>
</docProperties>
</document>
</documents>
</folder>
</objectStore>
</addml>
As you can see above document tag can appear many times. all the values I will be getting from variables like (String documentID = "1234"). I need help in how to loop the elements and construct the above xml in java.
Any help is much appreciated.
Thanks, Mark
use DOM parser. consider
http://www.mkyong.com/java/how-to-create-xml-file-in-java-dom/
and
Xml file generator in java
Related
i need create next structure en xml
<ser:myobjet soapenv: encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
<xml xsi:type='xsd.string'>
<!^[CDATA[<!xml version="1.0" encoding="iso-8859-1"?>
<object>
<service>
<request>
<idservice>65445</idservice>
<date>14-08-2016</date>
<additionalData>
<user>user</user>
<city>mycity</city>
</additionalData>
</request>
</service>
</object>]]>
</xml>
See I have a father and his children, yet one of them has their own children
<request>
<idservice>65445</idservice>
<date>14-08-2016</date>
<additionalData>
<user>user</user>
<city>mycity</city>
</additionalData>
</request>
I'm really lost and do not know how to create that structure.
Someone knows or some example of how to create it?
As I return a CDATA me and I need access to those tags, any idea how to do it?
Thank you.
i want to bind this simple XML File in my java project:
<?xml version="1.0" encoding="UTF-8"?>
<itg>
<reader>
<chapter id="1">
<subchapter id="1"></subchapter>
<subchapter id="2"></subchapter>
</chapter>
<chapter id="2">
<subchapter id="1"></subchapter>
<subchapter id="2"></subchapter>
</chapter>
<chapter id="3"></chapter>
</reader>
<questions>
</questions>
</itg>
I use NetBeans, and actually i bind the XML File by parsing the xml file into a ArrayList, an bind the list.
It works, but it is possible to bind the xml File in a better way?
Thanks!
For this small XML (and not only) I would recommend that you take a look at JAXB. The two basic operations are marshalling (converting Java objects to XML data) and unmarshalling (converting XML data to Java objects) but verification and so on is also provided.
I am trying to copy a content from one xml to other xml using Xslt.
I need to copy content of file1
<?xml version="1.0"?>
<products author="Jesper">
<product>
<name>Delta</name>
<price>800</price>
<stock>
<price>13a</price>
</stock>
<place>Denmark</place>
</product>
</products>
to file 2. File2 has similar tags but order is jumbled,
<?xml version="1.0"?>
<products author="Jesper">
<product>
<stock>
<price>13d</price>
</stock>
<price>700</price>
<place>Copenhagen</place>
<name>Beta</name>
</product>
</products>
expected output
<products author="Jesper">
<product>
<stock>
<price>13a</price>
</stock>
<price>800</price>
<place>Denmark</place>
<name>Delta</name>
</product>
</products>
so basically I need to Iterate through file1 using for-each and then find the matching tag in file2 and copy the tag value. Not sure about an efficient way to do so ... Double iterating is inefficient. Any suggestion will be helpful.
This is a very broad question, but I'll try to give you some pointers that should get you started. You will probably want to use the doc() function to load the files since XSLT only allows you to iterate over a single "main" file. doc() loads a new file into a variable that you can apply templates to and so on. If you are concerned about the iteration performance, you should learn about xsl:key and the key() function, which build indexes that will help with that.
I'm working on a project that involves KML creation using Java. Currently, I'm fooling with the sample Java code from the KML example at Micromata Labs JAK Example. I tried to "extend" the code by adding multiple coordinates and getting two markers, but I could not get it to work. Can you please tell me how I can add multiple coordinates and put markers on them, and also, draw a line between the markers. Thank you for your help!
PS: I need to do this via the program. I saw sample code of them using DOM and XML, but not pure Java/JAK as such. Please guide me.
I got as far as this (updated):
kml.createAndSetDocument().withName("MyMarkers")
.createAndAddPlacemark().withName("London, UK").withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.126236, 51.500152);
kml.createAndSetDocument().withName("MyMarkers")
.createAndAddPlacemark().withName("Somewhere near London,UK").withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.129800,52.700152);
But I know I'm going wrong somewhere. Please point me in the right direction.
Here is the resulting KML output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Document>
<name>MyMarkers</name>
<Placemark>
<name>Somewhere near London, UK</name>
<open>1</open>
<Point>
<coordinates>-0.1298,52.700152</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I can't seem to access the Document again to add more placemarks. How do I do it?
Basically, you need to do:
Document document = kml.createAndSetDocument().withName("MyMarkers");
document.createAndAddPlacemark().withName("London, UK").withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.126236, 51.500152);
document.createAndAddPlacemark().withName("Somewhere near London,UK").withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.129800,52.700152);
Previously, you were creating a new document and setting it (as the only document!) in the kml object. Therefore, only the last entry was shown.
To put more than one Placemark in a KML file you need a Folder or a Document
A basic <kml> element contains 0 or 1 Feature
A Feature is an abstract element that can be a Placemark.
A Container extends Feature and
can be a Document or a Folder
To make a long story short, if you want multiple Placemarks, you need to include them in a Document or a Folder
<kml>
<Document>
<Placemark>
</Placemark>
...
<Placemark>
</Placemark>
</Document>
</kml>
The documentation is very bad.
final Kml kml = new Kml();
Document document = kml.createAndSetDocument();
listForms = formDAO.getAll();
for (Form list : listForms){
document.createAndAddPlacemark()
.withName(String.valueOf(list.getId()))
.withDescription(list.toStringKML())
.createAndSetPoint().addToCoordinates(-20.3978398, -43.5146653);
}
kml.setFeature(document);
kml.marshal(new File("test.kml"));
I am wirking with solr server. i want to fetch data from MySQL database to solr. the following is the db-data-config.xml:
<dataConfig>
<dataSource type="JdbcDataSource" driver="org.gjt.mm.mysql.Driver" url="jdbc:mysql://192.168.1.9:3306/angara" user="dev_user" password="ampliflex" />
<document>
<entity name="tdiamonds1" query="select UID_PK, ProductUID, name, price,Weight from tdiamonds">
</entity>
</document>
</dataConfig>
i want to know what <document> tag indicates here, can we give more then one tag here, if possible please refer me some good example.
<document> encapsulates one or more entity elements. You can also specify a name for the given document.