小编joe*_*e90的帖子

为什么不从Javascript数组中删除更改其长度?

我有一个数组:

data.Dealer.car[0]
data.Dealer.car[1]
data.Dealer.car[2]
Run Code Online (Sandbox Code Playgroud)

如果我这样做:

alert(data.Dealer.car.length);
delete data.Dealer.car[1];
alert(data.Dealer.car.length);
Run Code Online (Sandbox Code Playgroud)

它每次都给我相同的数量.删除的元素是否仍然存在?

javascript

12
推荐指数
4
解决办法
2万
查看次数

快速,轻量级的XML解析器

我有一个特定的格式XML文档,我将推动.此文档将始终为相同类型,因此非常严格.

我需要解析这个,以便我可以将它转换为JSON(嗯,一个稍微混淆的版本,所以其他人可以使用它与DOJO).

我的问题是,我是否应该使用非常快速的轻量级(不需要SAX等)XML解析器(任何想法?)或编写我自己的,基本上转换为StringBuffer并旋转数组?基本上,我假设所有HTML解析器都将通过字符串(或内存缓冲区)旋转并解析,从而产生输出.

谢谢

编辑

xml将介于3/4行到最大约50行之间(极端情况下).

java xml dojo json

10
推荐指数
2
解决办法
2万
查看次数

解析在元素中包含XML的XML,可以这样做

我有一个XML的"复杂项目",然后是一个包含许多其他信息的"workitem"(在xml中),我希望这包含一个包含xml中复杂项的字符串.

例如:

<inouts name="ClaimType" type="complex" value="<xml string here>"/>
Run Code Online (Sandbox Code Playgroud)

但是,尝试SAX和其他java解析器我无法让它处理这一行,它不喜欢字符串中的<或","我试图转义,并将"转换为".

反正有这个吗?或者我必须提出另一种解决方案吗?

谢谢

java xml

3
推荐指数
2
解决办法
1523
查看次数

JSON发帖,我推JSON太远了吗?

我只是想知道我是否将JSON推得太远了?如果有人之前打过这个?

我有一个xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<customermodel:Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:customermodel="http://customermodel" xmlns:personal="http://customermodel/personal" id="1" age="1" name="Joe">
<bankAccounts xsi:type="customermodel:BankAccount" accountNo="10" bankName="HSBC" testBoolean="true" testDate="2006-10-23" testDateTime="2006-10-23T22:15:01+08:00" testDecimal="20.2" testTime="22:15:01+08:00">
    <count>0</count>
    <bankAddressLine>HSBC</bankAddressLine>
    <bankAddressLine>London</bankAddressLine>
    <bankAddressLine>31 florence</bankAddressLine>
    <bankAddressLine>Swindon</bankAddressLine>
  </bankAccounts>
</customermodel:Customer>
Run Code Online (Sandbox Code Playgroud)

其中包含元素和属性....

当我转换为JSON时,我给了我:

{"customermodel:Customer":{"id":"1","name":"Joe","age":"1","xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","bankAccounts":{"testDate":"2006-10-23","testDecimal":"20.2","count":"0","testDateTime":"2006-10-23T22:15:01+08:00","bankAddressLine":["HSBC","London","31 florence","Swindon"],"testBoolean":"true","bankName":"HSBC","accountNo":"10","xsi:type":"customermodel:BankAccount","testTime":"22:15:01+08:00"},"xmlns:personal":"http://customermodel/personal","xmlns:customermodel":"http://customermodel"}}
Run Code Online (Sandbox Code Playgroud)

那么我也发送这个客户端..它转换为js对象(或其他)编辑一些值(元素),然后将其发送回服务器.

所以我得到了JSON字符串,并将其转换回XML:

<customermodel:Customer>
    <id>1</id>
    <age>1</age>
    <name>Joe</name>
    <xmlns:xsi>http://www.w3.org/2001/XMLSchema-instance</xmlns:xsi>
    <bankAccounts>
        <testDate>2006-10-23</testDate>
        <testDecimal>20.2</testDecimal>
        <testDateTime>2006-10-23T22:15:01+08:00</testDateTime>
        <count>0</count>
        <bankAddressLine>HSBC</bankAddressLine>
        <bankAddressLine>London</bankAddressLine>
        <bankAddressLine>31 florence</bankAddressLine>
        <bankAddressLine>Swindon</bankAddressLine>
        <accountNo>10</accountNo>
        <bankName>HSBC</bankName>
        <testBoolean>true</testBoolean>
        <xsi:type>customermodel:BankAccount</xsi:type>
        <testTime>22:15:01+08:00</testTime>
    </bankAccounts>
    <xmlns:personal>http://customermodel/personal</xmlns:personal>
    <xmlns:customermodel>http://customermodel</xmlns:customermodel>
</customermodel:Customer>
Run Code Online (Sandbox Code Playgroud)

并且有问题,似乎不知道元素/属性之间的区别所以我无法检查XSD以检查它现在是否有效?

这个问题有方法解决吗?

我不能成为第一个遇到这个问题的人吗?

json

2
推荐指数
1
解决办法
551
查看次数

XSLT帮助在java中运行

我是XSLT世界的新手,我基本上试图从HERE运行JSON转换

但是如果我使用这种方法:

TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(new StreamSource("src\\json\\xml-to-json.xsl"));
        transformer.transform(new StreamSource("src\\json\\xmltest.xml"), new StreamResult(new FileOutputStream("birds.out")));

        System.out.println(result);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

SystemId Unknown; Line #59; Column #127; Could not find function: if
SystemId Unknown; Line #59; Column #127; Extra illegal tokens: 'then', 'http://json.org/', ':', 'create-node', '(', '$', 'input', ',', 'false', '(', ')', ')', 'else', 'http://json.org/', ':', 'create-simple-node', '(', '$', 'input', ')'
SystemId Unknown; Line #59; Column #127; function token not found.
Run Code Online (Sandbox Code Playgroud)

如果我使用Saxon,我宁愿使用inbuit,因为许可,但只需调用它的主要工作:

String[] args = new String[2];
args[0]="d:\\xmltest.xml";
args[1]="d:\\xml-to-json.xsl";
net.sf.saxon.Transform.main(args);
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在Java中正确编码(不调用main),以便我可以存储结果. …

xslt json saxon

1
推荐指数
1
解决办法
1954
查看次数

标签 统计

json ×3

java ×2

xml ×2

dojo ×1

javascript ×1

saxon ×1

xslt ×1