System.FormatException当我尝试执行以下操作时,我会得到一个(例如):
TimeSpan ts = XmlConvert.ToTimeSpan("P72H");
Run Code Online (Sandbox Code Playgroud)
我已经调查了ISO8601标准,它似乎是正确的,但无论我做什么,我都无法解析它而不会抛出异常.
谢谢!
编辑:
例外细节:
System.FormatException was unhandled by user code
HResult=-2146233033
Message=The string 'P72H' is not a valid TimeSpan value.
Source=System.Xml
Run Code Online (Sandbox Code Playgroud) 使用Java DOM解析器解析XML文件会导致:
[Fatal Error] os__flag_8c.xml:103:135: An invalid XML character (Unicode: 0xc) was found in the element content of the document.
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xc) was found in the element content of the document.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
Run Code Online (Sandbox Code Playgroud) 我试图通过在jsp中编写一些代理代码,从我的计算机本地对其他域进行ajax调用.这是我调用proxy.jsp页面的jQuery AJAX代码.
var metadata = 'https://rest-search.host.com/machine/search/meta?id=';
var on_show_info= function() {
var AjaxCall = data + current_doc_info.id;
alert(AjaxCall);
request_meta_info = $.ajax({
url: "proxy.jsp?url=" + AjaxCall,
type: 'GET',
success: check,
error: error
});
};
Run Code Online (Sandbox Code Playgroud)
我的JSP文件是: -
<%@ page language="java" import="org.w3c.dom.*,javax.xml.parsers.DocumentBuilder,javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String urlToQuery = request.getParameter("url");
System.out.println("rj " +urlToQuery);
URL url = new URL(urlToQuery);
final String login ="user";
final String password ="pass";
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
}
});
URLConnection conn = url.openConnection(); …Run Code Online (Sandbox Code Playgroud) 我正在查看一些xml文件,但没有找到我的问题的答案:XML元素可以同时包含文本和子元素吗?
例如:
<tree>
<node1>
textTextText
<subnode1> text1 </subnode1>
<subnode2> text2 </subnode2>
</node1>
</tree>
Run Code Online (Sandbox Code Playgroud)
我总是看到这些:
<node2>
<sub1> text </sub1>
</node2>
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习android,并按照如何使用Google Maps API V.2的说明进行操作.但是,有关如何配置地图初始状态的说明(在developers.google.com中找到)建议在xml文件中定义名称空间,在本例中为"map".
下面的xml代码给出了错误"Unexpected namespace prefix"map" ".尝试定义片段标记内的xmlns:map会产生相同的错误,但使用"xmlns".
我显然在这里缺少一些基本的xml知识,有人可以帮助我吗?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto" <!-- Definition -->
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraBearing="112.5"/> <!-- PROBLEM -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) xml android xml-parsing android-layout google-maps-android-api-2
我试图用jsoup解析XML,但我找不到关于此任务的任何示例.
我的XML文档如下所示:
<?xml version="1.0" encoding="UTF-8">
<tests>
<test>
<id>xxx</id>
<status>xxx</status>
</test>
<test>
<id>xxx</id>
<status>xxx</status>
</test>
....
</tests>
</xml>
Run Code Online (Sandbox Code Playgroud)
它应该很简单,但我的尝试失败了.
码:
Element content = doc.getElementById("content");
Elements tests = content.getElementsByTag("tests");
for (Element testElement : tests) {
System.out.println(testElement.getElementsByTag("test"));
}
Run Code Online (Sandbox Code Playgroud) 我找不到这些解析技术的比较.哪一个最常用?
问候.穆斯塔法
我正在尝试创建一些xpath,它将找到所有a不包含img标签的标签,以便像这样的东西
<a href="http://aol.com">link</a>
Run Code Online (Sandbox Code Playgroud)
比赛,但是
<a href="http://yahoo.com"><img src="http://yahoo.com/logo.png"></a>
Run Code Online (Sandbox Code Playgroud)
才不是.
当然,我可以通过两部分搜索来完成此操作,但我确信必须有一些方法可以使用xpath执行此操作.
我使用PHP库生成XML,如下所示:
$dom = new DOMDocument("1.0","utf-8");
Run Code Online (Sandbox Code Playgroud)
执行上述操作会在页面中显示输出顶部的消息.
此页面包含以下错误:第274行第274505行的错误:PCDATA无效字符值27下面是第一个错误之前的页面呈现.
我尝试使用Tidy库进行纠正..使用iconv来获取UTF-8中的中文字符.
以下代码在Java 7中运行良好
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
String xmlString = '<xml ..... ';
StringReader reader = new StringReader(xmlString);
JAXBContext jc = JAXBContext.newInstance(MyClass.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
MyClass myClass = (MyClass) unmarshaller.unmarshal(reader);
....
Run Code Online (Sandbox Code Playgroud)
现在我们不得不升级到Java 8,现在我在执行代码时遇到了这个异常:
Sep 03, 2014 1:42:47 PM com.sun.xml.internal.bind.v2.util.XmlFactory createParserFactory
SCHWERWIEGEND: null
org.xml.sax.SAXNotRecognizedException: Feature: http://javax.xml.XMLConstants/feature/secure-processing
at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:100)
at com.sun.xml.internal.bind.v2.util.XmlFactory.createParserFactory(XmlFactory.java:114)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getXMLReader(UnmarshallerImpl.java:139)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:214)
Run Code Online (Sandbox Code Playgroud)
我知道,有一个问题,针对类似的问题,但退一步Java 7的是不是一个解决方案给我.
我试图添加以下maven依赖项
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但这没有改变结果,所以我删除了它(感谢@BlaiseDoughan的信息,这包含在Java 6中)
欢迎任何提示,非常感谢.