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.
Related
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
I use DOM parser to read data from XML file. I know how to read, modify and write back the data. However, I would like to know if it is possible to create an object from an XML file.
I have an XML file which looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE people SYSTEM "validator.dtd">
<people>
<student>
<name>John</name>
<course>Computer Technology</course>
<semester>6</semester>
<scheme>E</scheme>
</student>
<student>
<name>Foo</name>
<course>Industrial Electronics</course>
<semester>6</semester>
<scheme>E</scheme>
</student>
</people>
and I would like to make it an objects out of it so I can pass them around. Does a solution exist ?
Yes. This is possible through JAXB (Java API for XML binding)
All JAXB implementations provide a tool called a binding compiler to bind a XML schema in order to generate the corresponding Java classes.
For details refer: http://www.oracle.com/technetwork/articles/javase/index-140168.html#xmp1
You could have a look at XML beans or JAXB libraries. In case you don't have a schema file but have a sample XML file, you could create one using inst2xsd tool of xmlbeans. http://xmlbeans.apache.org/docs/2.0.0/guide/tools.html. This could get you started with the schema.
I have below xml. Namespace is missing in the below xml.
<?xml version="1.0" encoding="UTF-8"?>
<policy>
<num-drivers>123</num-drivers>
<risk-policy-ind>false</risk-policy-ind>
<premium-amt>23.00</premium-amt>
</policy>
Looking for java code to take the above xml as input and add namespace (xmlns) element to it? The expected output xml is as below:
<?xml version="1.0" encoding="UTF-8"?>
<policy xmlns="http://aaa.bbb.com">
<num-drivers>123</num-drivers>
<risk-policy-ind>false</risk-policy-ind>
<premium-amt>23.00</premium-amt>
</policy>
First of all, in the above xml, risk-policy-ind tag is not properly closed. In XML all tags are custom tags, they should close. Moreover,in xml, tags are performed without namespace.
If u just want to add xmlns attribute to policy tag, create policy element using w3c.dom.Element and set attribute using setAttribute function
my contacts.xml file is:
<?xml version="1.1" encoding="UTF-8" standalone="no" ?>
<Directory>
<Contacts DeviceID="" FolderID="" FolderName="">
<Contact contacttype="0" id="111" optype="0">
<FirstName>shiva1</FirstName>
<wsuniqueid>00000000A4DACC2711A8D24C9AC2C2999311125BC4306A00</wsuniqueid>
</Contact>
<Contact contacttype="0" id="222" optype="0">
<FirstName>shiva2</FirstName>
<wsuniqueid>00000000A4DACC2711A8D24C9AC2C2999311125BC4306A01</wsuniqueid>
</Contact>
</Contacts>
</Directory>
when i want to insert some node or data by query:
insert node <a/> into doc('contacts.xml')//Directory/Contacts/Contact[#id = '111']
from linux command it is giving error XQDY0084 ..
The error code is not related to the insertion (directly). It indicated you are using strict validation somewhere, and you are not adhering to the strict validation rules. Perhaps because the system cannot find an appropriate schema file in which Directory is a valid root element.
Namespace your elements, and use an appropriate XML Schema, or decide not to validate at all.
HTH!
We have an existing document tree. We want to wrap some of the elements inside this tree up within a element.
Depending on where in the tree we are, the element will hold very different content.
So I have a DocumentPromptLanguage class and a DocumentRouterLanguage class. They have different parents and different children but it makes sense that in XML they are both called <language>.
Is this possible without adapters or must the XML representation disambiguate by element name?
Sample:
<?xml version="1.0" encoding="utf-8"?>
<doc>
<info>
<language>
<iso639>en</iso639>
<value>This is a sample document</value>
</language>
<language>
<iso639>es</iso639>
<value>Se trata de un documento de muestra</value>
</language>
</info>
<someElement>
<route>
<language>
<iso639>en</iso639>
<possibleValues>Yes|No|Maybe</possibleValues>
<prefix>For</prefix>
</language>
<language>
<iso639>es</iso639>
<possibleValues>sí|not|tal vez</possibleValues>
<prefix>para</prefix>
</language>
<when>Tuesday</when>
<afterTime>17.30</afterTime>
<goto></goto>
</route>
</someElement>
</doc>
Yes the class mapped to the route element can have a property mapped with #XmlElement(name="language"), and so can the class mapped to the info element. This because the mappings are scoped by class.