开发者

javascript help - doing something new in a old school way

开发者 https://www.devze.com 2023-04-13 01:40 出处:网络
UPDATE : Some have said that they were able to get more than 1 childNode... Here is my fiddle - I am only getting 1 childNode to display.

UPDATE : Some have said that they were able to get more than 1 childNode... Here is my fiddle - I am only getting 1 childNode to display.

Where is the error?

ORIGINAL Question Below is a partial snippet of javascript code that I have inherited. Basically this function used to get XML data by calling an AJAX function. However, due to requirement changes I am generating an XML string and storing that string in hidden input variable on the screen (Classic ASP).

After looking closer at the original script I found that it would be nice if I could somehow pass my xml string into the cmdxml variable. However, when I set cmdxml equal to my xml string: cmdxml = $.parseXML(xmlVal); and then try to use the snippet below it only gets 1 child node. I've included a small snippet of the xml string that I'm passing below.

Old Javascript Function (partial) using cmdxml:

    if (req.responseXML!=null) {
        var PropName;
        var PropValue;              
        var cmdxml = req.responseXML.documentElement;   
        // read each document element child node in the XML document

    for (var c =0;c<cmdxml.childNodes.length;c++) {
            var m;
            var t = cmdxml.childNodes[c];   //req.responseXML.documentElement.childNodes[c]
            if (t!=null) {
            //console.log(t.nodeName);
            switch(t.nodeName) {     //req.responseXML.documentElement.childNodes[c].nodeName
                    case "RObject": {   //response object
                        var RObject = t;    
                    //req.responseXML.documentElement.childNodes[c].nodeName.attributes[2].value
                    var CtrlChangeType = RObject.attributes[2].value;
                        var CtrlObjName = RObject.attributes[1].value;
                        var Ct开发者_如何学GorlObjType = RObject.attributes[0].value;
                        var CtrlObj;

                    var RObjProp = RObject.getElementsByTagName("Property");
                    PropName =  RObjProp[0].attributes[0].value;
                        PropValue = getElementText(RObjProp[0].getElementsByTagName("Value")[0]);

                    switch (CtrlChangeType) {   //req.responseXML.documentElement.childNodes[c].nodeName.attributes[0].value
                        case "comboboxInsRow": {

Here is a snippet of my xml string that I'm passing:

<?xml version="1.0" ?><xCMDS><JCallBack ProgramName="x"><Value><![CDATA[top.closeCtrlLoading();]]></Value></JCallBack><RObject Type="E" Name="gH2ptObj_co_code" ChangeType="objProp" rowNum="" colNum=""><Property Name="value"><Value><![CDATA[]]></Value></Property></RObject>


parseXML returns an XMLDocument, . You'll need to set cmdxml zo $.parseXML('snippet').documentElement to access the childNodes(childNodes is a property of nodes, usually not available in documents) .

Your fiddle returns a childNode, but this is the root-element, you like to access the childNodes of the root-element.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号