I am trying to parse below xml using saxparse in java code but i get SAXParseException. xml looks fine. Not sure why i get this exception. Can anyone help me know what is the problem with my xml. Thanks in advance!
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:m0="http://schemas.compassplus.com/two/1.0/fimi_types.xsd" xmlns:m1="http://schemas.compassplus.com/two/1.0/fimi.xsd">
<env:Body>
<m1:UserDefinedRp>
<m1:Response Response="1" TranId="7643629" Ver="14.3" Product="XXX"/>
</m1:UserDefinedRp>
</env:Body>
</env:Envelope>
Below is the exception i get:
org.xml.sax.SAXParseException: Element type "env:Envelope" must be followed by either attribute specifications, ">" or "/>".
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213)
at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:579)
at org.apache.xerces.framework.XMLDocumentScanner.abortMarkup(XMLDocumentScanner.java:628)
at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1800)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:949)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
If you think it is correct XML (yes, it looks fine) try to check nonprintable chars, sometimes IDE or other editors add them. Try to check it.
Related
When marshalling an empty value, the XML generated looks something like:
<some_data>
<required_tag_with_data>Some data</required_tag_with_data>
<required_tag_without_data>
</some_data>
The output I'd like to see, however, is more like this:
<some_data>
<required_tag_with_data>Some data</required_tag_with_data>
<required_tag_without_data />
</some_data>
or this:
<some_data>
<required_tag_with_data>Some data</required_tag_with_data>
<required_tag_without_data></required_tag_without_data>
</some_data>
In the binding I've tried setting usage="required" and nillable="true" but that results in:
<some_data>
<required_tag_with_data>Some data</required_tag_with_data>
<required_tag_without_data xsi:nil="true">
</some_data>
Thanks in advance :)
It turns out that Jibx is not at fault.
I am using a Chrome plugin called Dev HTTP Client (https://plus.google.com/104025798250320128549) to view the output XML.
The plugin, it appears, applies some formatting to the XML but then drops off the closing forward slash in the scenario described above.
When viewing the raw output (in my IDE's debugger) it is as expected.
I have raised a bug report with the developer of DHC.
I have a problem with Apache Digester 3.2 I hope you can help me with:
The XML I have to parse contains the following lines (and much more):
<CountryName
code = "GFR"
name = "Germany"
IsTerritory = "False"
ProfileURL = "germany.doc"/>
The rules for the digester are given by another XML-file:
<pattern value="CountryName">
<object-create-rule classname="model.CodeNamePair"/>
<set-properties-rule/>
<set-next-rule methodname="addCountry"/>
</pattern>
This should create an Object of CodeNamePair (which contains a String 'code' and a String 'name', just like in the XML above.
The next method 'addCountry' is (hopefully) not relevant for this problem which follows now:
The digester is not able to parse this part. It throws a NoSuchMethodException with message:
"java.lang.NoSuchMethodException: Property IsTerritory can't be set"
Although I don't want to parse the IsTerritory property.
Do you know if (and how) I will be able to ignore this property?
Already now: Thank you very much (I hope my question is not written too complicated)
Try
<set-properties-rule>
<ignore attr-name="IsTerritory" />
</set-properties-rule>
instead of
<set-properties-rule/>
(Not tested)
Guys,
I´m writing an app which is a WebService but I´ve been facing a strange issue.
When I call the W.S I receive this error:
Exception Description: The object [2013-08-04T12:00:00:00], of class [class java.lang.String], from mapping [org.eclipse.persistence.oxm.mappings.XMLDirectMapping[dateEvent-->dateEvent/text()]] with descriptor [XMLDescriptor(br.com.gvt.armanagementapp.service.to.ReceivableInvoiceIn --> [DatabaseTable(ns0:receivableInvoiceIn)])], could not be converted to [class java.util.Calendar].
But my Objet ReceivableInvoiceIn there isn´t an attribute with java.util.Calendar there is an atributte java.util.Date
Has anyone faced this issue?
My environment is Weblogic12c with maven
I found the problem. I think is a bug on Weblogic12c1.1 when you perform a simple test with Webblogic ´s WebService Client , it puts a blank spaces into the tag like this:
<code>
<dateEvent>
<!--date time format: yyyy-MM-ddTHH:mm:ss-->
1999-12-24T22:00:00
</dateEvent>
</code>
The solution is split the blank spaces:
<code>
<dateEvent>1999-12-24T22:00:00</dateEvent>
</code>
I am trying to retrieve the value of an attribute from an xmel file using XPath and I am not sure where I am going wrong..
This is the XML File
<soapenv:Envelope>
<soapenv:Header>
<common:TestInfo testID="PI1" />
</soapenv:Header>
</soapenv:Envelope>
And this is the code I am using to get the value. Both of these return nothing..
XPathBuilder getTestID = new XPathBuilder("local-name(/*[local-name(.)='Envelope']/*[local-name(.)='Header']/*[local-name(.)='TestInfo'])");
XPathBuilder getTestID2 = new XPathBuilder("Envelope/Header/TestInfo/#testID");
Object doc2 = getTestID.evaluate(context, sourceXML);
Object doc3 = getTestID2.evaluate(context, sourceXML);
How can I retrieve the value of testID?
However you're iterating within the java, your context node is probably not what you think, so remove the "." specifier in your local-name(.) like so:
/*[local-name()='Header']/*[local-name()='TestInfo']/#testID worked fine for me with your XML, although as akaIDIOT says, there isn't an <Envelope> tag to be seen.
The XML file you provided does not contain an <Envelope> element, so an expression that requires it will never match.
Post-edit edit
As can be seen from your XML snippet, the document uses a specific namespace for the elements you're trying to match. An XPath engine is namespace-aware, meaning you'll have to ask it exactly what you need. And, keep in mind that a namespace is defined by its uri, not by its abbreviation (so, /namespace:element doesn't do much unless you let the XPath engine know what the namespace namespace refers to).
Your first XPath has an extra local-name() wrapped around the whole thing:
local-name(/*[local-name(.)='Envelope']/*[local-name(.)='Header']
/*[local-name(.)='TestInfo'])
The result of this XPath will either be the string value "TestInfo" if the TestInfo node is found, or a blank string if it is not.
If your XML is structured like you say it is, then this should work:
/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='TestInfo']/#testID
But preferably, you should be working with namespaces properly instead of (ab)using local-name(). I have a post here that shows how to do this in Java.
If you don't care for the namespaces and use an XPath 2.0 compatible engine, use * for it.
//*:Header/*:TestInfo/#testID
will return the desired input.
It will probably be more elegant to register the needed namespaces (not covered here, depends on your XPath engine) and query using these:
//soapenv:Header/common:TestInfo/#testID
I am getting response XML, in that I want to add xmlns attribute in each child node which is generated.
Present output:
<createProfileResponse xmlns="http://services.profile.webservices.ecaas.com">
<createProfileReturn>STRING</createProfileReturn>
</createProfileResponse>
Required output:
<createProfileResponse xmlns="http://services.profile.webservices.ecaas.com">
<createProfileReturn xmlns="">STRING</createProfileReturn>
</createProfileResponse>
How do I do this?
NOTE: I've used JAXB to generate the XML.
The problem is that you need to have "createProfileReturn" in the blank namespace, and you explicitly put the default namespace in a non-blank namespace in the surrounding tag.
If the XML parser is fully compliant you could create a "ecaaas" global namespace and use
<ecaas:createProfileResponse>
<createProfileReturn/>
</ecaas:createProfileResponse>
HIThanks for helping out, actually this we done in coding through the saopBinding class.
But we also modified the server-config.wsdd file I really didnt understand why we need wsdd file..
This gives only the service?.
Anil