Java XSL Transformation complaining about binding prefix to namespace - java

I try to transform a XML-document which is a TCX-file from a Garmin Watch with XSL and the javax.xml.transform.Transformer. This is the document (shorten):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
<Activities>
<Activity Sport="Running">
<Id>2014-08-23T15:36:15.000Z</Id>
<Lap StartTime="2014-08-23T11:50:34.000Z">
<TotalTimeSeconds>3181.0</TotalTimeSeconds>
<DistanceMeters>7620.0</DistanceMeters>
<MaximumSpeed>21.887998580932617</MaximumSpeed>
<Calories>386</Calories>
<AverageHeartRateBpm>
<Value>119</Value>
</AverageHeartRateBpm>
<MaximumHeartRateBpm>
<Value>167</Value>
</MaximumHeartRateBpm>
<Intensity>Active</Intensity>
<TriggerMethod>Manual</TriggerMethod>
<Track>
<Trackpoint>
<Time>2014-08-23T11:50:34.375Z</Time>
<Position>
<LatitudeDegrees>48.17259333333333</LatitudeDegrees>
<LongitudeDegrees>10.191565</LongitudeDegrees>
</Position>
<AltitudeMeters>542.5505981445312</AltitudeMeters>
<DistanceMeters>0.0</DistanceMeters>
<HeartRateBpm>
<Value>70</Value>
</HeartRateBpm>
<SensorState>Absent</SensorState>
</Trackpoint>
[...]
</Track>
<Notes>Note</Notes>
</Lap>
<Notes>Note</Notes>
<Training VirtualPartner="false">
<Plan Type="Workout" IntervalWorkout="false">
<Name>Running</Name>
<Extensions/>
</Plan>
</Training>
<Creator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Device_t">
<Name>Polar V800</Name>
<UnitId>0</UnitId>
<ProductID>13</ProductID>
</Creator>
</Activity>
</Activities>
<Author xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Application_t">
<Name>no application</Name>
</Author>
</TrainingCenterDatabase>
I use the javax.xml.transform.Transformer for this task and get a strange error. The transformer gives me the following error message:
Element "xmlns:xsi" cannot have "xmlns" as its prefix.
It belongs to the line:
<Creator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Device_t">
From my point of view, this line is valid. The given namespace is just bound to the prefix xsi. Is it necessary to configure the Transformer to detect it right or do I need to specify something in the xsl-file?
Thanks

Related

xml schema in jaxb java not getting expected output

My expected output is in this format of JAXB.
<?xml version="1.0" encoding="utf-8"?>
<req:ShipmentRequest xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com ship-val-global-req.xsd" schemaVersion="5.0">
<Request>
<ServiceHeader>
<MessageTime>2001-12-17T09:30:47-05:00</MessageTime>
<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>CustomerTest</SiteID>
<Password>alkd89nBV</Password>
</ServiceHeader>
</req:ShipmentRequest>
but i am able to get only
<?xml version="1.0" encoding="utf-8"?>
<ShipmentRequest xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com ship-val-global-req.xsd" schemaVersion="5.0">
<Request>
<ServiceHeader>
<MessageTime>2001-12-17T09:30:47-05:00</MessageTime>
<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>CustomerTest</SiteID>
<Password>alkd89nBV</Password>
</ServiceHeader>
</ShipmentRequest>
how can i add a prefix like "req:" as shown in the expected output as i am using jaxb to marshall and unmarshall

cvc-complex-type.2.4.a invalid content was found starting with element factory in faces-config.xml

I have this error in a eclipse project, imported from a Netbeans project, set as a maven and project facet to Dynamic Web Project ( CDI1.1, Java 1.8, JS 1.0, JSF 2.2, JAX-RS 2.0, JBoss Maven Integration 1.0 and JPA 2.1)
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>fr</supported-locale>
</locale-config>
<resource-bundle>
<base-name>Messages</base-name>
<var>messages</var>
</resource-bundle>
<factory>
<exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
</application>
</faces-config>
The answer is in the question, no node factory is allowed under the node application according to the XSD file http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd such that your XML file is invalid.
The list of supported elements under application is:
action-listener
default-render-kit-id
message-bundle
navigation-handler
view-handler
state-manager
el-resolver
property-resolver
variable-resolver
resource-handler
resource-library-contracts
system-event-listener
locale-config
resource-bundle
application-extension
default-validators
According to the XSD file, The node factory seems to be expected at the same level as application so directly under faces-config as next:
<faces-config ...
<application>
...
</application>
<factory>
<exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
</faces-config>

Find out wheter <?xml-stylesheet ?> node exists in xml-document

I've got a XML-document with this content:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="/Stylesheet.xsl" ?>
How can I find out using ANT's <xmltask> whether the <?xml-stylesheet ?> node already exists?
That's a special node type called processing instruction.
You can query it using XPath to find out if it exists and what its attributes are:
/processing-instruction('xml-stylesheet')

Error in weblogic.xml : cvc-complex-type.2.4.a: Invalid content was found starting with element 'prefer-application-packages'

I am using springs source tool suite.
I am getting an error in weblogic.xml file--
cvc-complex-type.2.4.a: Invalid content was found starting with element 'prefer-
application-packages'. One of '{"http://www.bea.com/ns/weblogic/weblogic-web-app":retain-
original-url, "http://www.bea.com/ns/weblogic/weblogic-web-app":show-archived-real-path-
enabled, "http://www.bea.com/ns/weblogic/weblogic-web-app":require-admin-traffic,
"http://www.bea.com/ns/weblogic/weblogic-web-app":access-logging-disabled}' is expected.
enter code here
and my weblogic.xml looks like this
<?xml version="1.0"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app
http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<jsp-descriptor>
<keepgenerated>true</keepgenerated>
<page-check-seconds>60</page-check-seconds>
<precompile>true</precompile>
<precompile-continue>true</precompile-continue>
</jsp-descriptor>
<container-descriptor>
<optimistic-serialization>true</optimistic-serialization>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>javax.persistence.*</package-name>
<package-name>org.apache.commons.*</package-name>
</prefer-application-packages>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
the error is shown at the beginning of tag..
weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
changed the namespace to the above one.. it worked now..
I don't know anything about weblogic, but the schema you reference at
http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd
shows what child elements are expected inside a container-descriptor element, and they don't permit a prefer-application-packages element.
Order should be same as given below
<wls:timeout-secs>1800</wls:timeout-secs>
<wls:cookie-path>/my</wls:cookie-path>
<wls:cookie-secure>true</wls:cookie-secure>
<wls:cookie-http-only>true</wls:cookie-http-only>
<wls:url-rewriting-enabled>false</wls:url-rewriting-enabled>

XSLT and Java: Default Namespace XMLNS

I'm new to XSLT and I'm trying to transform one XML file into another one. My problem is that there is one namespace 'xmlns' without any prefix in the original xml file and when I transform it to another one through xslt then nothing happens but if I remove that xmlns namespace then it works out but actually I cannot modify the original .xml file since I'm bound to use that file only, so I have to keep xmlns in the original file as it is. So can anyone please suggest some modifications in my .xsl or java code to overcome this problem.
My Original XML namespace looks like-
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="eXeorm_sample4823c6301f29a89a4c1f"
xmlns:ims="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</manifest>
My desired xml is:
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="eXescorm_quiz4823c6301f29a8419515"
xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</manifest>
My Modified XSLT-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"
xmlns:ims="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="ims:manifest">
</xsl:stylesheet>
There's a search box at the top of this page: type "XSLT default namespace" and you will find hundreds of answers to this question.
Incidentally, your code is incredibly verbose. Instead of this:
<xsl:element name="item">
<xsl:attribute name="identifier">ITEM-eXeorm_sample4823c6301f29a89a4d27</xsl:attribute>
<xsl:attribute name="isvisible">true</xsl:attribute>
<xsl:attribute name="identifierref">RES-eXeorm_sample4823c6301f29a89a4d28</xsl:attribute>
</xsl:element>
use this:
<item identifier="ITEM-eXeorm_sample4823c6301f29a89a4d27" invisible="true"
identifierref="RES-eXeorm_sample4823c6301f29a89a4d28"/>

Categories