[Solved] Camunda spin xpath problem with namespaces

Hello!

I got a xml with a weird namespac and I would like to use xPath to get to some child element efficiently.

Problem is that the xPath doesnt find me anything. I have tried 2 things.

1 I have tried searching without a namespace like this. (Is there a better way to do it?)

SpinXmlElement xml = XML("<doc xmlns=\"urn:x-abc:r2:reg-doc:1551-fad.110.05:en:*\"><meta-data> <doc-name>SKELETON</doc-name></meta-data></doc>");
System.out.println(xml.xPath(“//doc-name”).element().textContent);

Stacktrace: nullpointer exception

2 I have tried searching without a namespace like this. (Is there a better way to do it?)

SpinXmlElement xml = XML("<doc xmlns=\"urn:x-abc:r2:reg-doc:1551-fad.110.05:en:*\"><meta-data> <doc-name>SKELETON</doc-name></meta-data></doc>");
System.out.println(xml.xPath(“//ns:doc-name”).ns(“ns”, “urn:x-abc:r2:reg-doc:1551-fad.110.05:en:*”).element().textContent);

Stacktrace Exception in thread “main” java.lang.AbstractMethodError: org.camunda.spin.xml.SpinXPathQuery.ns(Ljava/lang/String;Ljava/lang/String;)Lorg/camunda/spin/xml/SpinXPathQuery;

2.1 Im not sure how the ns(string,string) works cause I assumed it sort of does a search and replace. So I changed the document namespace to less special characthers but the ns command doesnt work for me.

SpinXmlElement xml = XML("<doc xmlns=\"test\"><meta-data> <doc-name>SKELETON</doc-name></meta-data></doc>");
System.out.println(xml.xPath(“//ns:doc-name”).ns(“ns”, “test”).element().textContent);

Stacktrace Exception in thread “main” java.lang.AbstractMethodError: org.camunda.spin.xml.SpinXPathQuery.ns(Ljava/lang/String;Ljava/lang/String;)Lorg/camunda/spin/xml/SpinXPathQuery;

Your second approach works fine for me in both 7.7.0 and 7.4.0 (Spin versions 1.3.1 and 1.2.1), i.e.

import org.camunda.spin.Spin;
import org.camunda.spin.xml.SpinXmlElement;

public class Main {

  public static void main(String[] args) {
    SpinXmlElement xml = Spin.XML("<doc xmlns=\"urn:x-abc:r2:reg-doc:1551-fad.110.05:en:*\"><meta-data> <doc-name>SKELETON</doc-name></meta-data></doc>");
    System.out.println(xml.xPath("//ns:doc-name").ns("ns", "urn:x-abc:r2:reg-doc:1551-fad.110.05:en:*").element().textContent());
  }
}

The exception sounds like a dependency issue to me. What’s the strack trace of the AbstractMethodError?

Nice to hear it’s working as intended.
The stack trace doesnt contain much. Maybe Im missing an option to activate more stack info.

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See SLF4J Error Codes for further details.
Exception in thread “main” java.lang.AbstractMethodError: org.camunda.spin.xml.SpinXPathQuery.ns(Ljava/lang/String;Ljava/lang/String;)Lorg/camunda/spin/xml/SpinXPathQuery ;
at com.ericsson.oss.services.mme.Temp.main(Temp.java:39)

Can you please share a minimal executable project on github that reproduces this? As I believe this is a setup issue, that way would be easiest to assist you.

Hello!
Issue been solved. I was running dependency camunda-spin-dataformat-all in some unknown version.

Thank you for the help @thorben.

This error is thrown when an application tries to call an abstract method without actual implementation. Abstract methods have no body and cannot be executed. This error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled. It usually happens after some library is upgraded while some is not. The dependencies are missing somehow. This means that you are using an old java version of an interface implementation which is missing a new interface method. For example java.sql.Connection interface got a new getSchema method in 1.7. If you have 1.6 JDBC driver and call Connection.getSchema you will get AbstractMethodError. So, make sure you have the latest jar file in your class path not a older copy.