What is the purpose of com.sun.org.apache.xpath.internal.operations.String?

后端 未结 2 1802
挽巷
挽巷 2021-02-08 17:40

I was writing a Java program, and when I tried to use a string, a suggestion that popped up was com.sun.org.apache.xpath.internal.operations.String.

What is

2条回答
  •  生来不讨喜
    2021-02-08 18:15

    You can work backwards based on the package name. The first piece that gives us a clue to what it does is Xpath. Then there's Apache, which is a the Apache Software Foundation. So it's an API called Xpath from Apache.

    XPath is a language for parsing and processing XML content. It has some simple capabilities such as math or data conversions. In this case, String is a unary operator that converts text to a String, as opposed to a Number or a boolean. It has one static method operate:

    public XObject operate(XObject right)
                throws TransformerException
    

    It takes an XObject of some unknown type and converts it to a String type.

    An example snippet of XPath for String conversion would be, at its barest:

    string($x) //convert variable x to a String
    

    You probably would never need to call this, seeing as it is part of an internal package. It is most probably used when interpreting XML to get the result as a String for use with other Xpath internal components. Indeed, the returned result is an XObject with a type associated to it, so interpreting it as a normal Java String would break something. It is nice to helpful to know that it's there, and it is public per design, but you'd ever use this in the real world unless you're expanding on the xpath API yourself.

    Source Package Tree

提交回复
热议问题