Tag: xml

使用Json-lib将XML转换为Json

我正在尝试在Android中执行一个项目,我从Web获取文档xml,我想在Json中进行转换。 我正在尝试这个: URL url; InputStream in; try { url = new URL(“http://www.aemet.es/xml/municipios/localidad_41091.xml”); in = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String result, line = reader.readLine(); result = line; while((line=reader.readLine())!=null){ result+=line; } XMLSerializer serializer = new XMLSerializer(); JSON json = serializer.read( result ); System.out.println(json.toString()); } catch (MalformedURLException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); […]

更新XML字符串

从给定的XML String,我必须更新结束日期值。 即使我在updateNodeValue()方法中更新xml,我的最终输出xml与输入xml相同。 有人能告诉我这段代码中的错误是什么 import java.io.StringReader; import java.io.StringWriter; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; public class MyClass{ static String strXml = “2013-12-022014-01-31”; public static void main(String[] args) throws Exception { System.out.println(strXml); Document doc = StringToDocument(strXml); updateNodeValue(doc); String […]

使用多个元素名称反序列化的简单xml框架

我试图使用Simple XML Framework将公共Web服务中的一些xml数据序列化为java对象。 问题是来自服务的不同方法返回具有不同元素名称的相同概念。 例如,方法A像这样返回元素foo foo value 而方法B返回 foo value 和方法C返回 foo value 是否有任何方法(多个名称注释等)将此xml反序列化为同一个类和相同的元素? 例如,将三个方法的结果反序列化为三个不同“Foo”对象中的相同“foo”元素(每个方法一个): @Root(name=”data”) public class Foo{ @Element public String foo; (…) }

org.apache.xml.security.c14n.CanonicalizationException:元素listFunctions具有相对名称空间:xmlns =“xxx_xxx_listFunctions”

我是Axis2和webservices的新手。 我有一个axis2网络服务。 当ws-security关闭时,事情运行正常。 打开ws-security时,我在服务器日志中收到以下exception。 我调试了没有调用的服务类方法。 附件是两个service.xmls使用。 调用webservice的客户端得到了后续的soap错误 – prolog中意外的EOF 我在tomcat中得到以下javaexception: org.apache.xml.security.c14n.CanonicalizationException: Element listFunctions has a relative namespace: xmlns=”test_vish_listFunctions” at org.apache.xml.security.c14n.implementations.Canonicalizer20010315.handleAttributesSubtree(Unknown Source) at org.apache.xml.security.c14n.implementations.CanonicalizerBase.canonicalizeSubTree(Unknown Source) at org.apache.xml.security.c14n.implementations.CanonicalizerBase.engineCanonicalizeSubTree(Unknown Source) at org.apache.xml.security.c14n.implementations.CanonicalizerBase.engineCanonicalizeSubTree(Unknown Source) at org.apache.xml.security.c14n.Canonicalizer.canonicalizeSubtree(Unknown Source) at org.apache.xml.security.utils.XMLUtils.outputDOM(Unknown Source) 当ws-security关闭且事情正常时,以下是server.xml This service is to get the list functions vish.web.ws.service.ListFunctionsService 打开ws-security时,以下是services.xml Service description for test_vish_listRoutines test.web.ws.service.ListRoutinesService true UsernameToken test.web.ws.control.PWCBHandler

Hibernate ConfigurationException:找不到cfg.xml资源 IntelliJ

我在IntelliJ IDE中遇到了hibernate.cfg.xml的问题。 这是我的hibernate配置文件: org.postgresql.Driver jdbc:postgresql://localhost/HIndex index_user password 1 org.hibernate.dialect.PostgreSQL82Dialect true create 这是我的应用程序类: package HIndexSaar.HIndex; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class HibernateManager { private static SessionFactory factory; public HibernateManager(){ // //* Setup the configuration. // Configuration config = new Configuration().configure(“hibernate.cfg.xml”).addAnnotatedClass(Person.class) .addAnnotatedClass(University.class).addAnnotatedClass(Publication.class); factory = config.buildSessionFactory(); } 我通过运行以下代码得到一个错误: package HIndexSaar.HIndex; public class […]

如何在JSP中从这个XML中提取值

我有一个XML如下(有100行): 任何人都可以告诉我如何循环它并从JSP中的上述XML文件中提取“counter”和“cash_filename”等属性。 到目前为止,我有以下代码: <% DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("http://localhost:8080/data.xml"); NodeList nl = doc.getElementsByTagName("cellimage"); for (int i = 0; i

使用XPATH表达式和Java解析XML文件

我想解析一个xml文件,我正在使用Java和xpath评估。 我想用xpath表达式输出当前的节点兄弟,而不使用getNextSibling()函数,这可能吗? 例如,如果我们读取name元素,我想添加xpath expression =“./ address”,以便在不使用getNextSibling()/的情况下输出“name”的兄弟。 xml文件如下: 我的代码如下: package dom_stack4; import org.w3c.dom.*; import javax.xml.xpath.*; import javax.xml.parsers.*; import java.io.IOException; import org.xml.sax.SAXException; public class Dom_stack4 { public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { // TODO code application logic here DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(“root.xml”); XPath […]

如何使用多行文本叠加图像(文本将位于canvas的中心)

我正在开发摄影应用程序,因为我用文本覆盖图像。 这是我的代码: Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.themes11); // create a mutable bitmap with the same size as the background image’s size bmOverlay = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_4444); // create a canvas on which to draw Canvas canvas = new Canvas(bmOverlay); TextPaint paint = new TextPaint(); paint.setColor(Color.RED); paint.setTextSize(40); paint.setFlags(Paint.ANTI_ALIAS_FLAG); // if the background image is defined in […]

用于Spring安全性的SpEL:将值从XML传递到基于Java的SpEL配置

我想将xml文件中指定的属性值传递给Java中的Spring表达式(SpEL)。 你能指出我如何实现这一目标吗? 为清楚起见,我提供了以下示例。 example.xml文件: 请记住,我有’用户’和’客户’模型类。 我希望通过以下方式使用预授权注释和Spring表达式来保护名为“edit”的方法。 @PreAuthorize(“(#user.userId == #customer.customerId)”) public Boolean edit(User user, Customer custmer) { return true; } 问题是,如何将userId和customerId的值从“example.xml文件传递到上面的表达式来比较这两个值,然后保护’edit’方法? 注意:我不想使用权限评估程序。 如果可以在不考虑许可评估者的情况下进行,请指出我。 非常感谢您的支持与合作!

Android锁屏应用按钮hover和序列

我正在开发一个Android锁屏应用程序。 但现在我被卡住了。 基本上我在屏幕上有一大堆按钮,当他们将手指从一个按钮拖到下一个按钮时,我需要能够注册,以及按顺序。 我怎样才能做到这一点? 我试图在OnTouch方法中使用MotionEvent.ACTION_MOVE,但它无法正常工作。 (它只适用于按钮1,因为我打印出logcat正在hover的按钮的ID,但它不会打印除按钮1之外的任何其他按钮) 请告诉我如何做到这一点?