0 Replies Latest reply on Mar 10, 2014 12:42 PM by LeftHead

    xmlElement added outside it's parent

    LeftHead Level 1

      Hi everybody

       

      Stuck once more with my XML process. My question title is maybe not clear, here is the explanation :

       

      Before launching my function (see below), my XML is just basic <p> in wich I want to tag character styles. Work fine except when the italic text is starting my paragraph. In this case, the <i> tag is not added inside the <p> tag but before the <p> tag.

       

      Any ideas are welcome

       

      When italic is in the middle of the paragraph (correct) :

      <p></p>                                                                           (previous paragraph)

      <p>Regular text, <i>Italic text,</i> regular text.</p>       (current paragraph)

      <p></p> (next paragraph)                                                (next paragraph)

       

      When italic is the beginning of the paragraph (not correct) :

      <p></p>                                                                           (previous paragraph)

      <i>Italic text</i>                                                              (italic outside the <p> tag)         

      <p> , regular text</p>                                                      (current paragraph)

      <p></p> (next paragraph)                                                (next paragraph)

       

       

       

       

      function caraToXml() {
          app.findTextPreferences = NothingEnum.nothing;
          app.findTextPreferences.fontStyle = "Italic";
          var myFindTexts = myDoc.findText();
          if (myFindTexts.length > 0) {
              for (var i = 0; i < 2; i++) {
                  myText = myFindTexts[i];
                  myXmlElement = myFindTexts[i].associatedXMLElements[0];
                  alert(myXmlElement.markupTag.name); // return "p" for all cases
                  myXmlElement = myXmlElement.xmlElements.add({markupTag:"i", xmlContent:myText});
                  alert(myXmlElement.markupTag.name); // return "i"  for all cases
                  myXmlElement = myXmlElement.parent;
              }
          }
      }