在Freemarker模板中访问带有命名空间的DOM元素(Accessing DOM element with namespace in Freemarker template)
我有以下XML
<wmi xmlns="http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/XMLSchema/fulfillment/v1/order/orderShipment OrderShipmentNotification.xsd"> <wmiHeader> <fileID>693401.20160229.130342.3541254</fileID> <version>2.0.0</version> <messageType>FSN</messageType> <genDate>2016-02-29T13:03:42Z</genDate> <from> </from> </wmiHeader> <orderShipNotification> <shipmentHeader dateTimeCreated="2016-02-29T13:03:42Z" requestNumber="2574445351883" /> <shipmentDetails actualShipmentDateTime="2016-02-29T12:18:54Z" carrierCode="XX" carrierMethodCode="XX-01"> <shipmentPackDetails trackingNumber="9361289672090007124848" trackingURL="https://example.com/go/TrackConfirmAction_input?qtc_tLabels1=323434"> <shipmentPackLineDetails requestLineNumber="1" partnerItemID="FXT-CC-LB" itemQtyShipped="1" /> </shipmentPackDetails> </shipmentDetails> </orderShipNotification> </wmi>
当我尝试访问时,我在Freemarker模板中收到错误。
${orderShipNotification.shipmentDetails.@actualShipmentDateTime[0]!""}
如果我从文档中删除命名空间,它工作正常。 我从XML中删除了以下内容
xmlns="http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/XMLSchema/fulfillment/v1/order/orderShipment OrderShipmentNotification.xsd"
我做了一些调查。 这是一个ftl指令。 但目前尚不清楚这将如何解决问题。 请让我知道如何访问属性。
http://freemarker.incubator.apache.org/docs/ref_directive_ftl.html#ref.directive.ftl
I have the following XML
<wmi xmlns="http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/XMLSchema/fulfillment/v1/order/orderShipment OrderShipmentNotification.xsd"> <wmiHeader> <fileID>693401.20160229.130342.3541254</fileID> <version>2.0.0</version> <messageType>FSN</messageType> <genDate>2016-02-29T13:03:42Z</genDate> <from> </from> </wmiHeader> <orderShipNotification> <shipmentHeader dateTimeCreated="2016-02-29T13:03:42Z" requestNumber="2574445351883" /> <shipmentDetails actualShipmentDateTime="2016-02-29T12:18:54Z" carrierCode="XX" carrierMethodCode="XX-01"> <shipmentPackDetails trackingNumber="9361289672090007124848" trackingURL="https://example.com/go/TrackConfirmAction_input?qtc_tLabels1=323434"> <shipmentPackLineDetails requestLineNumber="1" partnerItemID="FXT-CC-LB" itemQtyShipped="1" /> </shipmentPackDetails> </shipmentDetails> </orderShipNotification> </wmi>
I am getting error in Freemarker template when I am trying to access.
${orderShipNotification.shipmentDetails.@actualShipmentDateTime[0]!""}
If I delete the namespaces from the document it is working fine. I deleted the following content from the XML
xmlns="http://www.exmple.com/XMLSchema/fulfillment/v1/order/orderShipment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/XMLSchema/fulfillment/v1/order/orderShipment OrderShipmentNotification.xsd"
I did some investigation. The is a ftl directive. But it is still not clear how this will solve the problem. Please let me know how I can access the attributes.
http://freemarker.incubator.apache.org/docs/ref_directive_ftl.html#ref.directive.ftl
原文:https://stackoverflow.com/questions/35712198
最满意答案
数据库使用索引 。 这样,它可以快速找到与给定用户ID相关的数据。
取决于索引结构,占用空间等...有一个增益,即它不是搜索N列,而是搜索 - 例如 -
log(N)
。 通过二十亿行的二分法搜索N = 100,000,000,000
将会
Search(N) : search log2(N) = search (36 rows)
相反,搜索10 ^ 12行,只需要分析36行。
在你提到的情况下,朋友,每个用户可能有几个朋友,所以
user1 => (userX, userY, userZ, ...) userX => (userU, userV, user1, ...)
意思是user1是userX,userY等的朋友...即你没有每个用户的唯一索引。 但是每个用户都有一个唯一的索引。
在Mysql上会是
UNIQUE(user1,user2)
意味着情侣(user1,user2)在表格中只有一次。 语法是
CREATE UNIQUE INDEX friendsindex ON friends(user1,user2)
friendsindex是索引名称, 朋友是表。 或者如您所说,将表主键声明为
(user1,user2)
(每个表的主键是唯一的)。-
赢得游戏的策略基于相同的原则,该策略包括找到给定对象的确切价格。 假设价格在1到10000之间。你告诉价格,处理程序说
+
或-
。 您必须尽可能少地尝试查找价格。 例如价格是6000。您可以从
1
开始并将所有价格都提供到6000
(即6000次尝试),但您也可以继续进行二分法
- 你:5000
- 游戏玩家:+
- 7500或(10000 - 5000)/ 2
- -
- 6250或(7500 - 5000)/ 2
- -
- 等等...
在每次迭代时将剩余范围除以2。 而不是6000次尝试,您可以在12次尝试中找到(log2(6000))。
-
关于对数
例如,如何在
2^x = 1024
找到x? 或者x = log2(1024)
表示基数2中的对数为1024 (答案:10)。 在我们的故事中,具有基于二叉树的索引的1024行表需要10次尝试(最大)才能找到正确的元素(而不是1024最大值)。The database makes use of indexes. This way it can find quickly data related to a given userID.
Depending on the index structure, space occupation etc... there is a gain, i.e. instead of searching N columns, it searches - for instance -
log(N)
. A search by dichotomy of 100 billions rowsN = 100,000,000,000
would be
Search(N) : search log2(N) = search (36 rows)
Instead a searching 10^12 rows, only 36 rows have to be analyzed.
In the case you mention, friends, each user may have several friends, so
user1 => (userX, userY, userZ, ...) userX => (userU, userV, user1, ...)
meaning user1 is friend with userX, userY etc... ie you don't have a unique index per user. But you have a unique index per couple of users.
on Mysql that would be
UNIQUE(user1,user2)
meaning the couple (user1,user2) is only once in the table. The syntax would be
CREATE UNIQUE INDEX friendsindex ON friends(user1,user2)
friendsindex being the index name, friends being the table. Or as you said, declaring the table primary key to be
(user1,user2)
(primary keys are unique per table).--
The strategy to win a game that consists of finding the exact price of a given object is based on the same principle. Say the price is between 1 and 10000. You tell a price, and the handler says
+
or-
. You have to find the price in as less tries as possible. E.g. the price is 6000.You could start from
1
and give all prices until6000
(ie 6000 tries), but you could also proceed by dichotomy
- you: 5000
- gamer: +
- 7500 or (10000 - 5000)/2
- -
- 6250 or (7500 - 5000)/2
- -
- etc...
you divide the remaining range by 2 at each iteration. Instead of 6000 tries, you can find in 12 tries (log2(6000)).
--
About logarithms
For instance, how to find x in
2^x = 1024
? Orx = log2(1024)
meaning logarithm of 1024 in base 2 (answer: 10). In our story, a 1024 rows table having an index based on a binary tree would need 10 tries (max) to find the right element (instead of 1024 max).
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
dict对象的开销很大。 它取决于您的Python版本和您的系统架构,但取决于Python 3.5 64位 In [21]: sys.getsizeof({}) Out[21]: 288 所以猜测: 250*36e6*1e-9 == 9.0 因此,如果我创建了很多字典,那么这是我的内存使用量的下限(以千兆字节为单位) ,而不是list ! 不要将字典用作记录类型,而不是真正的用例,请使用namedtuple 。 为了得到这个比较的一个视图,让我们设置一个等效的元组列表: In [23]: Record ...
-
执行大量插入(Performing massive insert)[2019-11-18]
您可以使用JDBC进行多次插入,如下所示使用批量插入。 import java.sql.Connection; import java.sql.Statement; //... Connection connection = new getConnection(); Statement statement = connection.createStatement(); for (Employee employee: employees) { String query = "insert int ... -
大规模的ORM和继承(Massive ORM and inheritance)[2022-03-30]
我想我现在要和Dapper一起去: http://code.google.com/p/dapper-dot-net/source/browse/Tests/Tests.cs Dapper绝对是数据库独立的,它处理继承 在上面的Tests.cs中搜索TestInheritance()以获取示例。 I think I'm going to go with Dapper for now: http://code.google.com/p/dapper-dot-net/source/browse/Tests/Tes ... -
这在很大程度上取决于您正在进行的搜索类型。 如果您的数据都是ID查找,那么将它放在RAM中可能会更快。 如果您的数据都是全扫描(没有索引),那么将它放在RAM中可能会更快。 如果您的数据使用索引,那么将其放入数据库可能会更快。 当然,数据库的大部分吸引力都是索引和通用查询接口,因此您必须权衡这些接口与原始速度的重要性。 如果不确切知道数据的性质和要对其进行的查询,就无法真正回答这个问题。 线上时间有其成本,BSON < - >本地编组也是如此,但索引搜索可以是O(log n),而不是通过简单的内存数据进行愚 ...
-
Tekpub MVC 3系列使用Massive进行数据访问,代码可以在这里找到 - https://github.com/tekpub/mvc3 The Tekpub MVC 3 series uses Massive for the data access, code can be found here - https://github.com/tekpub/mvc3
-
ASP.NET Massive - 如何创建数据库以显示VIEW(ASP.NET Massive - How to create database to display VIEW)[2023-08-31]
代码更新后,更新到OP评论 杰德,把你的MoviesController改成这个 public class MoviesController : Controller { public ActionResult Index() { MovieTable dbMovies = new MovieTable(); dbMovies.All(); return View(dbMovies); } ... } 访问TekPub.com ... -
Oracle已经在Java中提供了JavaDB。 它是Apache Derby的Oracle打包版本,Apache Derby是Apache的开源嵌入式数据库。 您无需添加外部库即可使用它。 请查看此处了解详细信息: http : //www.oracle.com/technetwork/java/javadb/overview/faqs-jsp-156714.html JavaDB is already provided by Oracle in Java. It is the Oracle packag ...
-
您可以使用反向索引的概念。 它可能是这样的: 对文件进行排序。 对于字母表中的每个字符,请保留特定字符出现在特定位置的第一行和最后一行。 对于某个单词,获取所有范围并计算交集。 顺序很重要。 如果交叉点为空,请保留前一个。 如果最后交叉点为空,则该单词不存在。 例如:您计算了字符a出现在单词的第一个位置的范围(第一行和最后一行)。 对于第二个位置也是如此,依此类推。 您对字母表中的所有字符执行相同操作。 我们假设你想要“苹果”这个词。 您可以找到a出现在第一个位置的范围(设置A)。 p在第二个(设置B)和第 ...
-
数据库使用索引 。 这样,它可以快速找到与给定用户ID相关的数据。 取决于索引结构,占用空间等...有一个增益,即它不是搜索N列,而是搜索 - 例如 - log(N) 。 通过二十亿行的二分法搜索 N = 100,000,000,000 将会 Search(N) : search log2(N) = search (36 rows) 相反,搜索10 ^ 12行,只需要分析36行。 在你提到的情况下,朋友,每个用户可能有几个朋友,所以 user1 => (userX, userY, userZ, ...) ...