麻烦insertChildAfter对XML的actionsctipt 3麻烦、insertChildAfter、actionsctipt、XML

2023-09-09 21:56:20 作者:对的时间对的人

我有一个很大的麻烦,非常嵌套在我的XML的现有节点之后插入一个孩子。我试图插入下方object3_LIST3另一个IObject节点。

我试过相同的方案having在AS3 这一带insertChildBefore和insertChildAfter麻烦。这始终输出不定,我似乎无法弄清楚为什么..谁能帮助?

如果我跟踪contentNode和parentNode,它输出:

  object3_LIST3
 

 <对象>
  < IObject> object3_LIST3< / IObject>
< /对象>
 
我的编码习惯 配置规范

好像没有变化都对文档所作的...

  VAR contentNode:XML = xml.Menu.menuArr.HeadMenuItem [1] .subMenu.subMenuItem [1] .objects [0];
变种parentNode:XML = xml.Menu.menuArr.HeadMenuItem [1] .subMenu.subMenuItem [1] .objects.IObject [0];
XML = parentNode.insertChildAfter(contentNode,的xmlString);
跟踪(XML);
 

 < PandemicMenu>
    <菜单>
        < menuArr>
            < HeadMenuItem>
                <子>
                    < IObject>
                        object1_LIST1
                    < / IObject>
                    < IObject>
                        object2_LIST1
                    < / IObject>
                    < IObject>
                        object3_LIST1
                    < / IObject>
                < /子菜单>
            < / HeadMenuItem>

            < HeadMenuItem>
                <子>
                    < IObject>
                        object1_LIST2
                    < / IObject>
                    < subMenuItem>
                        <对象>
                            < IObject>
                                object2_LIST2
                            < / IObject>
                        < /对象>
                    < / subMenuItem>
                    < subMenuItem>
                        <对象>
                            < IObject>
                                object3_LIST3
                            < / IObject>
想在这里插入新IObject
                        < /对象>
                    < / subMenuItem>
                < /子菜单>
            < / HeadMenuItem>
        < / menuArr>
    < /菜单>
< / PandemicMenu>
 

解决方案

您的父节点和子节点切换。你的孩子节点是:

  VAR contentNode:XML = xml.Menu.menuArr.HeadMenuItem [1] .subMenu.subMenuItem [1] .objects [0];
 

这将跟踪具有以下一个 contentNode.toXMLString()

 <对象>
  < IObject> object3_LIST3< / IObject>
< /对象>
 

由于文档状态:如果提供child1,但它不能在XML对象存在,XML对象不修改并返回undefined。的http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/XML.html#insertChildAfter%28%29

这个问题可能是你要求的子节点查找其父节点,它无法找到,因此原来是不变。请尝试以下操作:

  VAR parentNode:XML = xml.Menu.menuArr.HeadMenuItem [1] .subMenu.subMenuItem [1] .objects [0];
变种contentNode:XML = xml.Menu.menuArr.HeadMenuItem [1] .subMenu.subMenuItem [1] .objects.IObject [0];
XML = parentNode.insertChildAfter(contentNode,的xmlString);
跟踪(XML);
 

我所做的只是切换parentNode和contentNode XML对象的内容。

I'm having a lot of trouble with inserting a child after an existing node that is VERY nested in my XML. I'm trying to insert another IObject node beneath object3_LIST3.

I've tried the same scheme as having trouble with insertChildBefore and insertChildAfter in AS3 with this. This always outputs undefined and I can't seem to figure out why.. Can anyone help?

If I trace contentNode and parentNode, it outputs:

object3_LIST3

and

<objects>
  <IObject>object3_LIST3</IObject>
</objects>

As if no changes were made at all to the document...

var contentNode:XML = xml.Menu.menuArr.HeadMenuItem[1].subMenu.subMenuItem[1].objects[0];
var parentNode:XML = xml.Menu.menuArr.HeadMenuItem[1].subMenu.subMenuItem[1].objects.IObject[0];
xml = parentNode.insertChildAfter( contentNode, xmlString );
trace(xml);

<PandemicMenu>
    <Menu>
        <menuArr>
            <HeadMenuItem>
                <subMenu>
                    <IObject>
                        object1_LIST1
                    </IObject>
                    <IObject>
                        object2_LIST1
                    </IObject>
                    <IObject>
                        object3_LIST1
                    </IObject>
                </subMenu>
            </HeadMenuItem>

            <HeadMenuItem>
                <subMenu>
                    <IObject>
                        object1_LIST2
                    </IObject>
                    <subMenuItem>
                        <objects>
                            <IObject>
                                object2_LIST2
                            </IObject>
                        </objects>
                    </subMenuItem>
                    <subMenuItem>
                        <objects>
                            <IObject>
                                object3_LIST3
                            </IObject>
Want to insert new IObject here
                        </objects>
                    </subMenuItem>
                </subMenu>
            </HeadMenuItem>
        </menuArr>
    </Menu>
</PandemicMenu>

解决方案

Your parent node and child nodes are switched. You child node is:

var contentNode:XML = xml.Menu.menuArr.HeadMenuItem[1].subMenu.subMenuItem[1].objects[0];

Which would trace the following with a contentNode.toXMLString():

<objects>
  <IObject>object3_LIST3</IObject>
</objects>

Since the docs state: "If child1 is provided, but it does not exist in the XML object, the XML object is not modified and undefined is returned." http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/XML.html#insertChildAfter%28%29

The problem could be that you are asking the child node to look for its parent node, which it can't find, and so the original is unmodified. Try the following:

var parentNode:XML = xml.Menu.menuArr.HeadMenuItem[1].subMenu.subMenuItem[1].objects[0];
var contentNode:XML = xml.Menu.menuArr.HeadMenuItem[1].subMenu.subMenuItem[1].objects.IObject[0];
xml = parentNode.insertChildAfter( contentNode, xmlString );
trace(xml);

All I did was switch the content of the parentNode and contentNode XML objects.

 
精彩推荐