This is my Response String from HTTP Post Method
1) <?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Open</string>
2) <?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">Close</string>
But I want only the Selected Or Result String from above lines
like from 1 response) I only want Open
from 2 response) I only want Close
How I can get this.
please reply
you can use kXML2 xml parsing api
If your handset supports JSR 172 you can follow this example to parse the data out. Otherwise you will need to write your own rudimentary string splitting/tokenizing. If you can guarantee the data is always in the format you've given, it won't be very hard.
Related
I am very new at Kotlin. I am wondering if this is possible to do it in Kotlin.
I have a request that is basically a POST to an endpoint, it sends information as part of the body, something like the following:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE...">
<some more tags...>
<request>
<clientAuth>
<client>
{client-id}
</client>
</cientAuth>
....
So I basically received some parameters (Like client-id) and I need to form this xml (as far as I am doing it at postman) and send the request.
Checking some libraries I noticed with retrofit is sort of possible, but I have no idea, is it really possible?
I know for "form url enconder" requests is simpler by using #FormUrlEncoded but not sure if there is one for xmls...
So far I got this:
an interface...
#POST("user-endpoint")
fun clientRequest(
#Field("clientId") clientId: String
): Deferred<Response<Void>>
and I invoke clientRequest from other function.
Testing the logic works fine for endpoints without parameters, but I have no idea how to send that xml, is it even possible?
I find out I can use tickaroo to represent my body as an object and then use retrofit without problem.
I'm running Mule 3.8 CE and my JAXB context and marshaller always create files declared like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
However the files are always UTF-16, and they get marshalled to utf-16, but the declaration says otherwise and I haven't found a way to solve that. I'm not sure how to set properties on my marshaller in Mule?
Feels a little stupid to have an external script just for replacing that string.
Regards
I'm trying to make a section of my SOAP request look like this:
<![CDATA[<?xml version="1.0" encoding="UTF-8"?><placeholder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WirelessEdgeInfo_v1_0.xsd"/>]]>
However, it looks like this after it has been escaped by underlying JAXB:
<![CDATA[<?xml version="1.0"
encoding="UTF-8"?> <placeholder
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="WirelessEdgeInfo_v1_0.xsd"/>]]>
I have looked at numerous examples, such as using MOXy and also implementing a CharacterEscapeHandler adapter or XmlAdapter HOWEVER the problem is the same for ALL these implementations. That is, it always comes down to this:
marshaller.setProperty(CharacterEscapeHandler.class.getName(),
new XmlCharacterHandler());
Setting a property in the marshaller.
However, in my case, I am using annotations generated through WSImport to generate my Web Services code dynamically when I execute the client SOAP call.
i.e. I do not have access to the marshaller object.
SO for me, how can I unescape the CDATA section of a String variable I need to pass in if I cannot set any property on the marshaller type?
Can I somehow "hack" or trick JAXB to tell it not to escape CDATA values? Or can I use annotations or somehow dynamically indicate unescaping?
I tried the following Adapter via annotation but of course this did not work:
#XmlJavaTypeAdapter(value=CDATAAdapter.class) //this is not working right now
protected String variableXmlContent;
variableXmlContent still ended up escaped. I also tried unescaping variableXmlContent and setting it as an input value, but it still came out the same way, unescaped.
An XML element value containing <, >, & is escaped by the marshaller using <, >, &.
Thus, if the XML element should contain
<![CDATA[ ... ]]>
the result in the XML file will be
<![CDATA[ ... ]]>
I suspect that the text to be passed as an XML element is
<?xml version="1.0" ... v1_0.xsd"/>
Now if I had to write this by hand into an XML file, I'd write it into a "CDATA section", but a (JAXB) marshaller will simply treat those three characters as I described before, and that's it.
<?xml version="1.0" ... v1_0.xsd"/>
It is pointless to try and make any XML marshaller use the CDATA mechanism, and there is no such thing as a "CDATA value" requiring special treatment - so there is no such special treatment.
I have the same problem as Set request character encoding of JSF input submitted values to UTF-8 in GlassFish, the submitted values arrive as Mojibake. However, the answer is targeted at GlassFish and I'm using JBoss AS 7.
I've already specified the JDBC connection URL to use UTF-8:
jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8
And in top of my JSF page:
<?xml version='1.0' encoding='UTF-8' ?>
How can I solve the same problem in JBoss AS 7? Or better, in a more generic way so that it works in all servers?
The question which you linked to has already excluded the DB encoding from being the cause because the problem already occurs during printing/redisplaying the submitted value before saving in DB. Thus, the problem is in HTTP request encoding.
Your JDBC connection URL with the charset specified,
jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8
only tells the MySQL JDBC driver to use UTF-8 to decode values in SQL queries before sending it to DB. This is not only completely beyond JSF's scope, but this is also not the cause of your problem, provided that you're absolutely positive that you've the same problem as in the linked question.
Your XML prolog with the charset specified,
<?xml version='1.0' encoding='UTF-8' ?>
only tells the XML parser to use UTF-8 to decode the XML source before building the XML tree around it. The XML parser actually being used is SAX as internally used by Facelets during JSF view build time. This part has completely nothing to do with HTTP request/response encoding and is thus very unlikely the cause of your problem.
None of them sets the HTTP request encoding, while you need to set the HTTP request encoding. The question which you linked to already shows how to do that for the Glassfish server. In your case, you're however using JBoss AS server. The Glassfish-specific setting is then inapplicable and JBoss doesn't support anything like that. You'd need to bring in a custom servlet filter to do the job. E.g.
#WebFilter("/*")
public class CharacterEncodingFilter implements Filter {
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
// ...
}
In standalone.xml, add atributte url-charset="UTF-8" in the tag http-listener name="default", and add atributte default-encoding="UTF-8" in the tag servlet-container.
Adding this to JBOSS_HOME/standalone/configuration/standalone.xml solved it for me:
<system-properties>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
</system-properties>
Got it from https://developer.jboss.org/message/643825#643825
Sorry in advance if this is a noob question.
All kml files start with roughly the same two lines:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
In the second line there is a reference to a web address which contains the schema for kml.
Am i to understand that this is contacted every time a kml file is
read ?
Secondly, is it possible (and how) to not have to contact
this (and other) addresses ?
The xmlns reference in a KML file only defines the XML namespace which happens to be associated with an XML Schema that defines that namespace.
Google Earth or Google Maps do NOT download the KML schema every time a KML file is accessed. In fact, it won't ever download the XML schema. The namespace just tells GE how to handle the file.
It just so happens that the Namespace URI for KML is a URL that redirects to the appropriate XML Schema.
In fact the complete schema reference for KML would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2
http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
...
</kml>
A description of XML namespaces can be found here:
http://www.w3.org/TR/REC-xml-names/#sec-namespaces
On a related note the standard icons you can use for your KML placemarks (e.g. http://maps.google.com/mapfiles/kml/shapes/airports.png) are likewise never downloaded by the Google Earth client. Those images are part of the installed Google Earth application from which Google Earth maps URLs to the local image file.