用于XML读取器的XML标记中的EXTJS 4.2转义冒号(:) [英] EXTJS 4.2 escape colon (:) in XML Tag for XML Reader

查看:85
本文介绍了用于XML读取器的XML标记中的EXTJS 4.2转义冒号(:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将atom pub CMIS 1.0绑定加载到EXTJS中,并且标记中的冒号正在阻止XML阅读器执行其工作.例如,xml看起来像:

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cmis="http://docs.oasis-         open.org/ns/cmis/core/200908/" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:app="http://www.w3.org/2007/app">
  <atom:author>
      <atom:name>system</atom:name>
   </atom:author>
   <atom:id>http://chemistry.apache.org/MTAz</atom:id>
   <atom:published>2013-11-28T00:01:22Z</atom:published>
   <atom:title>Folder1</atom:title>
   <app:edited>2013-11-28T00:01:22Z</app:edited>
   <atom:updated>2013-11-28T00:01:22Z</atom:updated>
   <cmisra:object xmlns:ns3="http://docs.oasis-open.org/ns/cmis/messaging/200908/">
      <cmis:properties>
         <cmis:propertyId queryName="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Types" localName="cmis:allowedChildObjectTypeIds" propertyDefinitionId="cmis:allowedChildObjectTypeIds">
            <cmis:value>*</cmis:value>
         </cmis:propertyId>
         <cmis:propertyId queryName="cmis:objectTypeId" displayName="Type-Id" localName="cmis:objectTypeId" propertyDefinitionId="cmis:objectTypeId">
            <cmis:value>cmis:folder</cmis:value>
         </cmis:propertyId>
         <cmis:propertyString queryName="cmis:path" displayName="Path" localName="cmis:path" propertyDefinitionId="cmis:path">
            <cmis:value>/Root/396271/Folder1</cmis:value>
         </cmis:propertyString>
         <cmis:propertyString queryName="cmis:name" displayName="Name" localName="cmis:name" propertyDefinitionId="cmis:name">
            <cmis:value>Folder1</cmis:value>
         </cmis:propertyString>
..... etc.

例如,如果我考虑一个简单的示例

    <?xml version="1.0" encoding="UTF-8"?>
<users>
    <user attr="test ed">
        <id:number>1</id:number>
        <name>Ed Spencer</name>
        <email>ed@sencha.com</email>
    </user>
    <user attr="test abe">
        <id:number>2</id:number>
        <name>Abe Elias</name>
        <email>abe@sencha.com</email>
    </user>
</users>

我使用EXTJS代码

Ext.onReady(function () {
   Ext.define('User', {
        extend: 'Ext.data.Model',
        autoload: true,
        fields: [{  name: "id", mapping: 'id:number'},
                         {  name: "name", mapping: 'name'},
                         {  name: "email", mapping: 'email'},
                         {  name: "attr", mapping: '@attr'}]
    });

    var store = Ext.create('Ext.data.Store', {
        model: 'User',
        proxy: {
            type: 'ajax',
            url : 'users.xml',
            reader: {
                type: 'xml',
                record: 'user',
                root: 'users'
            }
        }
    }); 

    store.load();

});

对于ID或备用代码的映射,我该怎么办?

fields: [{  name: "id", mapping: 'id:number'} ????? escape the ':' some how?

我试图避免编写尽可能多的自定义XML解析代码,而是依靠EXTJS阅读器,并且CMIS 1.1浏览器绑定不适用于我的ECM.

我发现该解决方案在EXTJS 4中解决,但在我熟悉的早期版本(3.4)中没有解决:在EXTJS 4 DomQuery中引入

因此,如果示例XML具有定义的名称空间,例如xmlns:id="http://my.example.com/id

然后,具有从之前修改过的名称空间的XML是:

<?xml version="1.0" encoding="UTF-8"?>
<users xmlns:id="http://my.example.com/id">
    <id:user attr="test ed">
        <id:id>1</id:id>
        <id:name>
            <id:first attr2="test ed 2">Ed</id:first>
            <id:last>Spencer</id:last>
        </id:name>
        <id:email>ed@sencha.com</id:email>
    </id:user>
    <id:user attr="test abe">
        <id:id>2</id:id>
        <id:name>
            <id:first attr2="test ed 2">Abe</id:first>
            <id:last>Elias</id:last>
        </id:name>
        <id:email>abe@sencha.com</id:email>
    </id:user>
</users>

这样下面的EXTJS代码将可以工作fields: [{ name: "id", mapping: 'id|id'}

那是完整的解决方案是

<!DOCTYPE html>
<html>
<head>
<link href="http://cdn.sencha.com/ext/gpl/4.2.1/resources/css/ext-all.css" rel="stylesheet" />
<script src="http://cdn.sencha.com/ext/gpl/4.2.1/ext-all.js"></script>
<script>
function getResult()
{
 document.getElementById("demo").innerHTML= 
         "<p>First Record Id is: " + test.data.items[0].data.id + "</p>" +
         "<p> First Name is: " + test.data.items[0].data.first + "</p>" +
         "<p> Last Name is: " + test.data.items[0].data.last + "</p>" +
         "<p> Email is: " + test.data.items[0].data.email + "</p>" +
         "<p> Attribute 1 is: " + test.data.items[0].data.attr + "</p>" +
         "<p> Attribute 2 is: " + test.data.items[0].data.attr2 + "</p>";
}

var test;

Ext.onReady(function () {
   Ext.define('User', {
        extend: 'Ext.data.Model',
        autoload: true,
        fields: [{  name: "id", mapping: 'id|id'},
                         {  name: "first", mapping: 'id|name>id|first'},
                         {  name: "last", mapping: 'id|name>id|last'},
                         {  name: "email", mapping: 'id|email'},
                         {  name: "attr", mapping: '@attr'},
                         {  name: "attr2", mapping: "id|name>id|first[@attr2='test ed 2']"}]
    });

    var store = Ext.create('Ext.data.Store', {
        model: 'User',
        proxy: {
            type: 'ajax',
            url : 'users.xml',
            reader: {
                type: 'xml',
                record: 'id|user',
                root: 'users'
            }
        }
    }); 

    store.load();

    test = store;
});
</script>
</head>
<body>

<h1>EXTJS Example</h1>
<p id="demo">Here we try to load XML into an EXTJS XML Reader</p>

<button type="button" onclick="getResult();">getResult</button>

</body>
</html> 

还要注意,如果在定义命名空间之前在根元素中使用了命名空间,则XML阅读器中的根定义需要使用:而不是|.字符即 root: 'id:users'

I am trying to load atom pub CMIS 1.0 binding into EXTJS and the colons in the tags are stopping the XML reader from doing its work. For instance the xml looks like:

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cmis="http://docs.oasis-         open.org/ns/cmis/core/200908/" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:app="http://www.w3.org/2007/app">
  <atom:author>
      <atom:name>system</atom:name>
   </atom:author>
   <atom:id>http://chemistry.apache.org/MTAz</atom:id>
   <atom:published>2013-11-28T00:01:22Z</atom:published>
   <atom:title>Folder1</atom:title>
   <app:edited>2013-11-28T00:01:22Z</app:edited>
   <atom:updated>2013-11-28T00:01:22Z</atom:updated>
   <cmisra:object xmlns:ns3="http://docs.oasis-open.org/ns/cmis/messaging/200908/">
      <cmis:properties>
         <cmis:propertyId queryName="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Types" localName="cmis:allowedChildObjectTypeIds" propertyDefinitionId="cmis:allowedChildObjectTypeIds">
            <cmis:value>*</cmis:value>
         </cmis:propertyId>
         <cmis:propertyId queryName="cmis:objectTypeId" displayName="Type-Id" localName="cmis:objectTypeId" propertyDefinitionId="cmis:objectTypeId">
            <cmis:value>cmis:folder</cmis:value>
         </cmis:propertyId>
         <cmis:propertyString queryName="cmis:path" displayName="Path" localName="cmis:path" propertyDefinitionId="cmis:path">
            <cmis:value>/Root/396271/Folder1</cmis:value>
         </cmis:propertyString>
         <cmis:propertyString queryName="cmis:name" displayName="Name" localName="cmis:name" propertyDefinitionId="cmis:name">
            <cmis:value>Folder1</cmis:value>
         </cmis:propertyString>
..... etc.

For example if I consider a simple example

    <?xml version="1.0" encoding="UTF-8"?>
<users>
    <user attr="test ed">
        <id:number>1</id:number>
        <name>Ed Spencer</name>
        <email>ed@sencha.com</email>
    </user>
    <user attr="test abe">
        <id:number>2</id:number>
        <name>Abe Elias</name>
        <email>abe@sencha.com</email>
    </user>
</users>

And I use EXTJS code

Ext.onReady(function () {
   Ext.define('User', {
        extend: 'Ext.data.Model',
        autoload: true,
        fields: [{  name: "id", mapping: 'id:number'},
                         {  name: "name", mapping: 'name'},
                         {  name: "email", mapping: 'email'},
                         {  name: "attr", mapping: '@attr'}]
    });

    var store = Ext.create('Ext.data.Store', {
        model: 'User',
        proxy: {
            type: 'ajax',
            url : 'users.xml',
            reader: {
                type: 'xml',
                record: 'user',
                root: 'users'
            }
        }
    }); 

    store.load();

});

What do I put down for the mapping for id, or alternate code?

fields: [{  name: "id", mapping: 'id:number'} ????? escape the ':' some how?

I am trying to avoid writing a lot of custom XML parsing code if possible and rely on the EXTJS reader, and the CMIS 1.1 browser binding is not available for my ECM.

解决方案

I have found the solution is addressed in EXTJS 4 but not in earlier versions that I am familiar with (3.4): The namespaces character | was introduced in EXTJS 4 DomQuery

So if the example XML has a defined namespace such as xmlns:id="http://my.example.com/id

Then the XML with the namespace modified from before is:

<?xml version="1.0" encoding="UTF-8"?>
<users xmlns:id="http://my.example.com/id">
    <id:user attr="test ed">
        <id:id>1</id:id>
        <id:name>
            <id:first attr2="test ed 2">Ed</id:first>
            <id:last>Spencer</id:last>
        </id:name>
        <id:email>ed@sencha.com</id:email>
    </id:user>
    <id:user attr="test abe">
        <id:id>2</id:id>
        <id:name>
            <id:first attr2="test ed 2">Abe</id:first>
            <id:last>Elias</id:last>
        </id:name>
        <id:email>abe@sencha.com</id:email>
    </id:user>
</users>

So that the following EXTJS code will then work fields: [{ name: "id", mapping: 'id|id'}

that is the full solution is

<!DOCTYPE html>
<html>
<head>
<link href="http://cdn.sencha.com/ext/gpl/4.2.1/resources/css/ext-all.css" rel="stylesheet" />
<script src="http://cdn.sencha.com/ext/gpl/4.2.1/ext-all.js"></script>
<script>
function getResult()
{
 document.getElementById("demo").innerHTML= 
         "<p>First Record Id is: " + test.data.items[0].data.id + "</p>" +
         "<p> First Name is: " + test.data.items[0].data.first + "</p>" +
         "<p> Last Name is: " + test.data.items[0].data.last + "</p>" +
         "<p> Email is: " + test.data.items[0].data.email + "</p>" +
         "<p> Attribute 1 is: " + test.data.items[0].data.attr + "</p>" +
         "<p> Attribute 2 is: " + test.data.items[0].data.attr2 + "</p>";
}

var test;

Ext.onReady(function () {
   Ext.define('User', {
        extend: 'Ext.data.Model',
        autoload: true,
        fields: [{  name: "id", mapping: 'id|id'},
                         {  name: "first", mapping: 'id|name>id|first'},
                         {  name: "last", mapping: 'id|name>id|last'},
                         {  name: "email", mapping: 'id|email'},
                         {  name: "attr", mapping: '@attr'},
                         {  name: "attr2", mapping: "id|name>id|first[@attr2='test ed 2']"}]
    });

    var store = Ext.create('Ext.data.Store', {
        model: 'User',
        proxy: {
            type: 'ajax',
            url : 'users.xml',
            reader: {
                type: 'xml',
                record: 'id|user',
                root: 'users'
            }
        }
    }); 

    store.load();

    test = store;
});
</script>
</head>
<body>

<h1>EXTJS Example</h1>
<p id="demo">Here we try to load XML into an EXTJS XML Reader</p>

<button type="button" onclick="getResult();">getResult</button>

</body>
</html> 

Also note that if the namespace is used in the root element before the namespace is defined then the root definition in the XML reader needs to use the : not the | character i.e root: 'id:users'

这篇关于用于XML读取器的XML标记中的EXTJS 4.2转义冒号(:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆