我试图XML使用SimpleXML解析来解析下面的内容.
我曾在不同的方法试图解析Attributes的Element,但无法在解析XML下方获得成功.
它会生成一个列表底部的错误.
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
<id>1</id>
<id_address_delivery xlink:href="http://abc.com/add/1">1</id_address_delivery>
<id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice>
</order>
</prestashop>
Run Code Online (Sandbox Code Playgroud)
Order.java
@Root(name="order")
@Namespace(reference="http://www.w3.org/1999/xlink",prefix="xlink")
public class Order {
@Element(name="id",required=true)
private int order_id;
@Element(name="id_address_delivery",required=false)
private int id_address_delivery;
@Attribute( name="href", required=false)
private String id_address_delivery_href;
@Element(name="id_address_invoice",required=false)
private int id_address_invoice;
@Attribute(name="href", required=false)
private String id_address_invoice_href;
}
Run Code Online (Sandbox Code Playgroud)
OrderObject.java
public class OrderObject
{
@ElementList(required=true, inline=true)
private List<Order> list = new ArrayList<Order>();
public List<Order>getList()
{
return this.list;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的例外是:
WARN/System.err(988): org.simpleframework.xml.core.PersistenceException:
Duplicate annotation of name 'href' …Run Code Online (Sandbox Code Playgroud) 我正在使用Retrofit 2.1.0和Retrofit SimpleXML Converter 2.1.0.我添加了simplexmlconverter来使用addConverterFactory方法改进实例.
XML如下
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>title</title>
<description></description>
<language>en-us</language>
<item>
<title>text</title>
<link>text</link>
<description>text</description>
<enclosure url="text" length="2043520" type="image/jpeg" />
<guid isPermaLink="false">text</guid>
<pubDate>Fri, 17 Jun 2016 11:43 EDT</pubDate>
<source url="text">text</source>
</item>
<item>
<title>text</title>
<link>text</link>
<description>text</description>
<enclosure url="text" length="1735257" type="image/jpeg" />
<guid isPermaLink="false">text</guid>
<pubDate>Thu, 16 Jun 2016 10:17 EDT</pubDate>
<source url="text"></source>
</item>
<item>
<title>text</title>
<link>text</link>
<description>text</description>
<enclosure url="text" length="3763157" type="image/jpeg" />
<guid isPermaLink="false">text</guid>
<pubDate>Wed, 15 Jun 2016 10:02 EDT</pubDate>
<source url="text">text</source> …Run Code Online (Sandbox Code Playgroud) 我正在使用SimpleXML框架反序列化后端答案.我对元素做了一些假设.有些元素不符合这些要求.例如,我希望一个元素有孩子<ID>和<face>.如果不允许我的用户查看特定元素,我可能会得到这样的答案:
<list>
<voucher type="hiddenobject">
<face>foo</face>
</voucher>
<voucher type="object">
<ID>42</ID>
<face>bar</face>
</voucher>
</list>
Run Code Online (Sandbox Code Playgroud)
这给了我以下反序列化类的ValueRequiredException:
@Root
class Voucher {
@Element(name="ID")
private String id;
@Element
private String face;
}
Run Code Online (Sandbox Code Playgroud)
我想用类型忽略这些对象hiddenobject.我了解了VisitorStrategy并实现了Visitor这样一个简单:
private static final class HiddenObjectVisitor implements Visitor {
@Override
public void read(Type type, NodeMap<InputNode> node) throws Exception {
String nodeType = node.getNode().getAttribute("type").getValue();
if (nodeType != null && nodeType.equals("hiddenobject")) {
Log.d(TAG, "skipping node " + node);
node.getNode().skip();
}
}
@Override
public void write(Type type, …Run Code Online (Sandbox Code Playgroud) 我正在考虑用新框架替换Apache Xerces-J,我正在考虑将Simple作为其继承者.
你有简单的经历吗?
它的优点和缺点是什么?
是否建议在servlet容器或应用程序服务器中使用企业软件?
我刚刚开始尝试使用SimpleXML进行Android开发,并认为它很顺利,直到遇到障碍.下面的代码产生了一个例外
W/System.err(665):org.simpleframework.xml.core.ConstructorException:无法构造内部类
我已经查看了关于内部类的问题,并认为我理解为什么你会使用它们(不是我的必然是有意的)但是尽管我移动我的代码以试图避免使用我仍然有点卡住并会感激任何帮助.
源代码:
public class InCaseOfEmergencyMedAlertAllergiesActivity extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Serializer serializer = new Persister();
InputStream xmlstream = this.getResources().openRawResource(R.raw.sample_data_allergies);
try {
medalertdata allergyObject = serializer.read(medalertdata.class, xmlstream);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setContentView(R.layout.allergies);
}
@Root
public class medalertdata {
@ElementList
private List<allergy> allergyList;
public List getAllergies() {
return allergyList;
}
}
@Root
public class allergy{
@Element
private String to;
@Element
private Boolean medical;
@Element
private String notes;
public allergy(String …Run Code Online (Sandbox Code Playgroud) 我正在使用Java和SimpleXML
我需要用SimpleXML解析这个XML文件:
<magazine title="N?mero 1" id="1">
<description>yutyutyu</description>
<miniature>http://web.com/scripts/getImage.php?idMagazine=1&resource=miniature.jpg</miniature>
<summary>2</summary>
<pages>
<page src="http://web.com/scripts/getImage.php?idMagazine=1&resource=page_001.jpg" id="1" thumbnail="http://web.com/scripts/getImage.php?idMagazine=1&resource=thumbnail_001.jpg">
<areas>
<area id="1">
<top>188</top>
<left>204</left>
<width>399</width>
<height>319</height>
<action type="openBrowser">http://www.web.com</action>
</area>
<area id="2">
<top>188</top>
<left>204</left>
<width>399</width>
<height>319</height>
<action type="openBrowser">http://www.web.com</action>
</area>
</areas>
</page>
<page src="http://web.com/scripts/getImage.php?idMagazine=1&resource=page_002.jpg" id="2" thumbnail="web.com/scripts/getImage.php?idMagazine=1&resource=thumbnail_002.jpg"/>
<page src="http://web.com/scripts/getImage.php?idMagazine=1&resource=page_003.jpg" id="3" thumbnail="web.com/scripts/getImage.php?idMagazine=1&resource=thumbnail_003.jpg"/>
</pages>
</magazine>
Run Code Online (Sandbox Code Playgroud)
我得到了这个例外:
03-22 16:02:35.072:WARN/System.err(1931):org.simpleframework.xml.core.ValueRequiredException:无法满足@ org.simpleframework.xml.ElementList(data = false,empty = true,entry = ,inline = false,name =,required = true,type = void)on field'area'public java.util.ArrayList com.Magazine.Page.areas for class com.Magazine.Page at line 1
杂志有一系列页面,每个页面都有一系列区域,每个区域都有一个动作类,其中包含更多内容.问题必须在区域数组上,因此它位于Page类中.
@Root (name="magazine")
public class FullMagazine {
@Attribute
String …Run Code Online (Sandbox Code Playgroud) I serialize this class using the Simple XML framework:
@Root
public class HowToRenderEmptyTag {
@Element(required=false)
private String nullString;
}
Run Code Online (Sandbox Code Playgroud)
I want to get:
<howToRenderNull>
<nullString/>
</howToRenderNull>
Run Code Online (Sandbox Code Playgroud)
But I get:
<howToRenderNull/>
Run Code Online (Sandbox Code Playgroud)
I have tried assigning an empty string:
@Root
public class HowToRenderEmptyTag {
@Element(required=false)
private String emptyString = "";
}
Run Code Online (Sandbox Code Playgroud)
But then I get one opening and one closing tag:
<howToRenderNull>
<emptyString></emptyString>
</howToRenderNull>
Run Code Online (Sandbox Code Playgroud)
使用XML并且更改客户端超出范围的客户端并没有错误地接受这一点.
关于如何获得单个空标签的任何想法?
我在我的应用程序中启用了proguard.每当我构建我的应用程序时,我都会遇到以下错误.
Constructor not matched for class com.acs.nomad.d.b.e
根据我的映射文件,这个引用的类如下所示
package com.my.package;
import java.util.ArrayList;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root (name = "folders")
public class Folders
{
@ElementList (entry = "contactFolder", required = false, inline = true)
private ArrayList<ContactFolder> contactFolder;
/**
* List of contact folders
*/
public ArrayList<ContactFolder> getContactFolder()
{
return contactFolder;
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有选项,因为这些url proguard-obfuscation-is-breaking
Android的proguard的-和keepclasseswithmembernames
似乎没什么用.我的Proguard.config文件是
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes Signature, *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application …Run Code Online (Sandbox Code Playgroud) 我正在使用Simple XML框架,只是重命名了一些XML布局,现在它们似乎不再起作用了.
这是我的XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<orderListReply id="R000000000006">
<order orderid="12" type="outbound" state="available">
<todo>2</todo>
<done>0</done>
<lines>1</lines>
<erporderid>0</erporderid>
</order>
</orderListReply>
Run Code Online (Sandbox Code Playgroud)
这是我的代码类定义:
@Root(name="orderListReply")
public class OrderListReplyTelegram extends Telegram {
@ElementList(name="order", inline=true, required=false)
private List<OrderListItem> orders;
...
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
org.simpleframework.xml.core.ElementException:元素'order'在第1行的类nl.minerall.sapphire.pocket.telegrams.OrderListReplyTelegram中没有匹配项
根据文档:https://kotlinlang.org/docs/reference/annotations.html
您可以将多个注释应用于单个站点使用目标,但是有没有办法将相同的注释应用于多个站点使用目标?
我的用例是使用SimpleXML的注释来装饰类.要使用一成不变的data class,你必须标注两者的字段和构造函数的参数:
data class Data(
@field:Element(name = "ID")
@param:Element(name = "ID")
val id: Int,
@param:Element(name = "TEXT")
@field:Element(name = "TEXT")
val text: String)
对于具有许多字段的数据类,您可以轻松地获得与实际代码一样多3倍的注释,并且最好消除重复.当你必须使用复杂的注释时,这尤其令人讨厌,因为ElementUnion它可以是多个线路.
simple-framework ×10
java ×5
xml ×5
android ×4
xml-parsing ×2
annotations ×1
kotlin ×1
proguard ×1
retrofit ×1
retrofit2 ×1
visitor ×1