Change tag name <Emp> to <Employee> while marshaling in jibx? - jibx

I have a scenario where the XML may be like <emp><name></name></emp> etc i want to
change the tags to <employee> while marshaling is this possible ??? Please help

Related

Generation of XSLT From XML

I have an XML File with very large content.
I had an xsd file for that xml file.
For example : Please visit this link
XML CONTENT : http://formalmind.com/sites/default/files/blog/manual-testing.reqif
XSD For that XML : https://www.omg.org/spec/ReqIF/20110401/reqif.xsd
I need to display that xml in HTML page. For that i need XSLT.
Is it possible to generate XSLT for the given XML Automatically ? or is there is any other way to display in html Page?
Html Result Should be like
HTML_OUTPUT_IMAGE
Thanks
Sivabalakrishnan
Yes, this is possible, but it's not clear that it's a useful approach. What information in the schema do you intend to use to generate your XSLT? You need to give some examples of constructs that you find in the schema, and the resulting XSLT rules that you want to generate.
There are two other options you should consider:
(a) writing a completely generic XSLT stylesheet, that handles any document regardless of its schema. For example, it could contain rules like this:
<xsl:template match="*[count(*)>1 and count(*)=count(distinct-values(*/node-name())]">
<table>
<xsl:for-each select="*">
<tr>
<td><xsl:value-of select="name()"/></td>
<td><xsl:apply-templates/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
This rule says that if you encounter an element with 2 or more element children, and all the children have distinct names, then display a table containing the element names in one column and their values in another.
(b) writing a generic schema-aware (XSLT 2.0) stylesheet that handles any input document, but uses schema information from the type annotations on validated nodes to decide what output to generate. For example you might have a rule like this:
<xsl:template match="#*[data(.) instance of xs:decimal]">
<xsl:value-of select="format-number(., '#,00', 'continental')"/>
</xsl:template>
which causes all decimal attribute values to be displayed using a format such as 3,14.

Trying to include Text and HTML inside XML schema but receiving failure

For a personal project I need to get information from an excel-sheet into xml-data (xml-schema needed) but if I try to validate it this error shows: "Non-HTML Content-Type: text/xml ."
The excel sheet includes information such as basic text, which is quite simple to transport into xml, but also has long html inside its cells which later should be used as content of a wordpress site/post. So this hmtl begins with visualcomposer elemnts like "[vc_row][vc_column][vc_column_text]" and further more contains very standard html elements like paragraphs or tables. All html is wrapped inside .
So I wonder if this could be the source of my problem as, with my very slim coding and debugging knowledge, this came in my mind first.
Some extra information:
the xml-schema is edited with Dreamweaver CC 2015 which also does the validation
the xml-file is characterized, with: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<materialData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Data inside the xml is structured like: <matData><ID>3001</ID><author>1</author> ... </matData>
I suspect what you need is to correctly enclose the values that will include html in cdata tags so there not seen as xml.
<exampleOfACDATA>
<![CDATA[
Since this is a CDATA section
I can use all sorts of reserved characters
like > < " and &
or write things like
<foo></bar>
but my document is still well formed!
]]>
</exampleOfACDATA>
see further details here
What does <![CDATA[]]> in XML mean?

Display XML in HTML website?

I'm looking to display some XML data but am having issues.
The xml data I'm looking to display is listed below:
<?xml version="1.0" encoding="utf-8"?>
<rooms>
<not_in_rooms>
</not_in_rooms>
<room name="Room1" description="text" users="0" id="r12" passworded="false" owner_username="admin" owner_siteid="" >
</room>
<room name="Room2" description="text" users="0" id="r13" passworded="false" owner_username="admin" owner_siteid="" >
<user ip="0.0.0.0" name="user1" siteId="" gender="male" cam="0" camIsPrivate="false" mic="0" >
</user>
</room>
I want to display the Room Names (i.e. Room1, Room2) and the users in each room (i.e. user1). I found generic xml to html tutorials but they don't explain what to do when there are attributes called within each element.
You could use several methods, based on what you want. Probably the easiest is XSLT or parsing it with a server-side scripting language like PHP.
XSLT is probably the closest to the "standard" way to do this. You just have to link to/embed the XML file and add an element to the file stating that you should use an XSLT stylesheet. There are plenty of XSLT tutorials online. If you are wondering about how to read all the attributes, see this question.
You could also use PHP to parse and output the HTML. This would be much more complicated but also more flexible.
You can use pure JavaScript and DOM parser to parse your XML.
Assume you have your XML as a variable in JavaScript:
var txt = "<XML></XML>"
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(txt);
}
//get take data..
xmlDoc.getElementsByTagName("Yourtagname")[0]
//Get Attribute Data...
xmlDoc.getElementsByTagName("Yourtagname")[0].getAttribute('YourAttributeInTag')
Here is a test fiddle from friends to try out.
http://jsfiddle.net/D2QpZ/

How to modify a XML element

I have a XML document file, and I want to do some changes or you can be say I want to change the values in these elements. But in this XML document there are some element which I can't understand means How can I change them. A sample code is here, Please see and let me know about that highlighted code, what is that type of code and how can i place my value in it.
<?xml version="1.0" encoding="ISO-8859-1"?>
<ServerConfig>
<rootLevel>ASIS</rootLevel>
<svpath>$../root/CMP/</svpath>
<vardes>Cobol</vardes>
<uname>root</uname>
<pname>ls_All</pname>
<param/> <!-- How can i edit this value and what is this, this type of element I have never seen before -->
</ServerConfig>
Please let me know about what type of this < param/> element in this xml and how can i change the value for it
I think <param> means parameter.
You can change/set the value like this:
<param>yourValue</param>

How do JAXB handles attribute in tag?

Suppose I have the following xml:
<root>
<tag1>value1</tag1>
<tag2 attr1="somevalue"></tag2>
</root>
I want to know how the JAXB handles the attribute of any tag, when it converts from xml to any any object. (I mean when it does unmarshalling)