E4X:在 XMLList 中插入节点以查找缺失的日期?
如果我有一个像这样的 XML 对象:
<a>
<u date="2009-04-10" value="543"/>
<u date="2009-04-11" value="234"/>
<u date="2009-04-13" value="321"/>
<u date="2009-04-14" value="66"/>
<u date="2009-04-16" value="234"/>
<t date="2009-04-01" value="43"/>
<t date="2009-04-02" value="67"/>
<t date="2009-04-03" value="432"/>
<t date="2009-04-08" value="123"/>
<t date="2009-04-09" value="65"/>
<l date="2009-04-01" value="12"/>
<l date="2009-04-02" value="76"/>
<l date="2009-04-03" value="123"/>
<l date="2009-04-04" value="6543"/>
<l date="2009-04-05" value="123"/>
<l date="2009-04-06" value="65"/>
<l date="2009-04-15" value="234"/>
<l date="2009-04-16" value="65"/>
</a>
此 XML 对象中有 3 个 XMLList。如果您注意到,日期之间有间隙。有没有办法将缺失的日期添加到每个 XMLList 中?值为 0。
另外,我不想在每个 XMLList 中的第一个和最后一个节点之前或之后添加任何日期...我只想填充每个节点之间缺少的日期。
我怎样才能做到这一点?
谢谢!!!
if I have an XML object like this:
<a>
<u date="2009-04-10" value="543"/>
<u date="2009-04-11" value="234"/>
<u date="2009-04-13" value="321"/>
<u date="2009-04-14" value="66"/>
<u date="2009-04-16" value="234"/>
<t date="2009-04-01" value="43"/>
<t date="2009-04-02" value="67"/>
<t date="2009-04-03" value="432"/>
<t date="2009-04-08" value="123"/>
<t date="2009-04-09" value="65"/>
<l date="2009-04-01" value="12"/>
<l date="2009-04-02" value="76"/>
<l date="2009-04-03" value="123"/>
<l date="2009-04-04" value="6543"/>
<l date="2009-04-05" value="123"/>
<l date="2009-04-06" value="65"/>
<l date="2009-04-15" value="234"/>
<l date="2009-04-16" value="65"/>
</a>
There is 3 XMLLists in this XML object. If you notice, the dates have gaps in them. Is there a way to add the missing dates to each XMLList? With a value of 0.
Also I do not want to add any dates before or after the first and last node in each XMLList...i just want to fill in the missing dates between each node.
How can I do that?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,这并不容易。 Actionscript 中没有 timedelta 类(如 Python)。这使得查找日期之间的距离变得有点痛苦。如果您可以保证日期始终在同一个月内(例如给定月份内的 1-31),那也不算太糟糕。然后你可以使用类似的东西:
这不会做一些花哨的事情,比如在月份或小于 10 的日期之前填充“0”。如果你的范围跨越月份障碍,它也不会处理。第一个问题很容易解决,所以我把它留给你。第二个根本不是很容易(特别是如果日期也跨越年份界限),我再次将其留给您。
It isn't that easy unfortunately. There is not timedelta class (like Python) in Actionscript. This makes finding the distance between dates a bit of a pain. It isn't too bad if you can guarantee that the dates will always be within the same month (e.g. 1-31 within a given month). Then you can use something like:
This doesn't do fancy stuff like pad "0" before months or dates that are less than 10. It also will not handle if your ranges cross month barriers. The first is really easy to fix so I leave it to you. The second is not very easy at all (especially if the dates cross year boundaries as well) and again I'll leave it to you.
如果您有 XML.ignoreWhitespace=true,那么您的 XML 将忽略这些间隙,并且 a.children() 将为您提供所有真实子节点的列表...如果为 false,您可以执行以下操作:
填充间隙对于空日期,请确保ignoreWhitespace为假,这样的事情应该可以工作:
If you have XML.ignoreWhitespace=true, then your XML will ignore those gaps, and a.children() will give you a list of all the real children nodes... If it's false, you can do this:
To fill the gaps with null dates make sure ignoreWhitespace is false, and something like this should work: