10 Replies Latest reply on May 23, 2006 11:46 PM by credev


      common no one can help out with xml issue? how to insert an element at a specific position?

      iam using this ArrayInsertAt(mydoc.employee.name, 2, XmlElemNew(mydoc, "PhoneNumber")
      but if the xml doc has only on2 element it alerts me that i cannot insert at position 2! but i need to insert it at the end!

      anyone help please!
        • 1. Re: HELP!
          dempster Level 1
          If you need to add something to the end of an array, use ArrayAppend.
          • 2. Re: HELP!
            BKBK Adobe Community Professional & MVP
            Are you looking for a way to add a 3rd element to an XML document that already has 2 elements? Something like this should do it:

            • 3. Re: HELP!
              credev Level 1
              Hello BKBK and thx for your reply!

              well my problem is how to insert an element between element1 and element2 ..
              can you help out with this?

              thank you alot for your time.
              • 4. Re: HELP!
                Stressed_Simon Level 1
                credev this is what you are trying to do:-

                • 5. Re: HELP!
                  credev Level 1
                  worked with this

                  ArrayInsertAt(xmlDoc.MyDoc.XmlChildren,#position# , XmlElemNew(xmlDoc,"TagTR"));

                  thnx guys
                  • 6. Re: HELP!
                    credev Level 1
                    yes exactly Stressed_Simon it works like that but now iam facing another problem.

                    when i put values to node like below and later when i do transformation for xmlDoc to HTML
                    xmlDoc.MyDoc.TagTR[#position#].XmlChildren[2].XmlText = "Palette Hétérogène";

                    i receive the following Palette Hétérogène its an encoding problem ... how can i solve it?
                    • 7. Re: HELP!
                      BKBK Adobe Community Professional & MVP
                      An idea

                      xmlDoc.MyDoc.TagTR[#position#].XmlChildren[2].XmlText = "Palette Hétérogène";

                      • 8. Re: HELP!
                        credev Level 1
                        BKBK i tried it but the output was the same

                        Palette Hétérogène


                        what do you think?
                        • 9. Re: HELP!
                          BKBK Adobe Community Professional & MVP
                          what do you think?
                          I think you did not put the output between cfoutput tags or within WriteOutput(). If you do, you will get Palette Hétérogène.

                          • 10. Re: HELP!
                            credev Level 1
                            BKBK this is not it! i already put cfoutput else it would have given me an error.

                            listen this is my function

                            <cffunction name="addNewElement" returntype="void">
                            <cfargument name="position" type="numeric" required="yes">
                            ArrayInsertAt(xmlDoc.MyDoc.XmlChildren,#position# , XmlElemNew(xmlDoc,"TagTR"));

                            StructInsert(xmlDoc.MyDoc.TagTR[#position#].XmlAttributes, "index", "index");

                            xmlDoc.MyDoc.TagTR[#position#].XmlChildren[1] = XmlElemNew(xmlDoc, "TagTD");
                            StructInsert(xmlDoc.MyDoc.TagTR[#position#].TagTD[1].XmlAttributes, "libelle", "Emballage");
                            xmlDoc.MyDoc.TagTR[#position#].XmlChildren[1].XmlText = "Palette Hétérogène";



                            and this is my xsl to transform it to html

                            <?xml version="1.0" encoding="ISO-8859-1" ?>
                            xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
                            xmlns=" http://www.w3.org/TR/REC-html40">

                            <xsl utput method="html" encoding="utf-8"/>
                            <xsl:template match="MyDoc">
                            <xsl:for-each select="TagTR">
                            <tr class="Arial_2_noir" height="10" align="left" valign="top" bgcolor="#CCCCCC">
                            <td><xsl:value-of select="TagTD[@libelle='Emballage']" /></td>

                            so in brief i have an xml Object (cfxml) which i added an element to it then i transform it to HTML and dump it to browser.

                            anyone can see why i have that problem? my output is "Palette Hétérogène" instead of "Palette Hétérogène"