4 Replies Latest reply on May 12, 2006 4:26 AM by Newsgroup_User

    Searching for and replacing text within tags

    Level 7
      This is somewhat related to a previous question I had.

      I have a string with a few lines like this:

      <?mso-infoPathSolution solutionVersion="1.0.0.1"
      ProductVersion="11.0.6565" ?>

      <?mso-application progid="InfoPath.Document" ?>

      What I want to do is create a general function that is similar to a
      wildcard, where it would search for the beginning of the string "<?mso"
      and the end of the string "?>" and then delete the entire string if it
      finds those parts.

      I'm thinking of using a combination of a For loop using indexOf for the
      found parts then using those values to slice out that line of text.

      Any pointers would be appreciated. Thanks!
      --
      =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
      remove "_nospam_" to send email

      Ian Kelleigh
      ian_nospam_@freehandsource.com

      "The FreeHand Source"
      http://www.FreeHandSource.com
        • 1. Re: Searching for and replacing text within tags
          Level 7
          This might suit your needs:


          var _xml = new XML();
          _xml.ignoreWhite = true;
          _xml.onData = function(src) {
          trace(src);
          if (src == undefined) {
          this.onLoad(false);
          } else {
          var _src = src;
          var _declOpen = "<?";
          var _declClose = "?>";

          // get the first xml declaration and store it for later use
          // we'll assume it's the xml declaration (could check if we wanted to)
          var _xmlDecl = _src.substring(_src.indexOf(_declOpen),
          _src.indexOf(_declClose)+_declClose.length);
          // remove the xml decl
          _src = _src.substring(_src.indexOf(_declClose)+_declClose.length);

          // remove all other decls from the string
          var _idx = _src.indexOf(_declOpen);
          while(_idx > -1){
          _src = _src.substring(0,_idx-1) +
          _src.substring(_src.indexOf(_declClose)+_declClose.length);
          _idx = _src.indexOf(_declOpen);
          }

          _src = _xmlDecl + _src;

          trace(_src);
          this.parseXML(_src);
          this.loaded = true;
          this.onLoad(true);
          }
          trace(this);
          trace(this.xmlDecl);
          };
          _xml.load("testdecl.xml");





          "Ian Kelleigh" <ian_nospam_@freehandsource.com> wrote in message
          news:e402hm$18g$1@forums.macromedia.com...
          > This is somewhat related to a previous question I had.
          >
          > I have a string with a few lines like this:
          >
          > <?mso-infoPathSolution solutionVersion="1.0.0.1"
          > ProductVersion="11.0.6565" ?>
          >
          > <?mso-application progid="InfoPath.Document" ?>
          >
          > What I want to do is create a general function that is similar to a
          > wildcard, where it would search for the beginning of the string "<?mso"
          > and the end of the string "?>" and then delete the entire string if it
          > finds those parts.
          >
          > I'm thinking of using a combination of a For loop using indexOf for the
          > found parts then using those values to slice out that line of text.
          >
          > Any pointers would be appreciated. Thanks!
          > --
          > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
          > remove "_nospam_" to send email
          >
          > Ian Kelleigh
          > ian_nospam_@freehandsource.com
          >
          > "The FreeHand Source"
          > http://www.FreeHandSource.com


          • 2. Re: Searching for and replacing text within tags
            Level 7
            YES! PERFECT! Thank you very much... spend a greater part of the day
            trying to get it. Knew I was on the right track but kept losing the XML
            Declaration part.

            Thank you again!

            --
            =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
            remove "_nospam_" to send email

            Ian Kelleigh
            ian_nospam_@freehandsource.com

            "The FreeHand Source"
            http://www.FreeHandSource.com
            • 3. Re: Searching for and replacing text within tags
              tonyhigham
              Well, Raymond beat me to it, but here's my version anyhow

              var myString:String = "Don't interrupt <?mso-application progid='InfoPath.Document' ?>my document, please."

              var tempArray:Array = myString.split(myString.slice(myString.indexOf("<?"),myString.indexOf("?>")+2))
              myString = tempArray.join("")
              • 4. Re: Searching for and replacing text within tags
                Level 7
                You're welcome.

                I read you're original post and it seemed odd. But apparently, flash's xml
                parser bombs out and returns status code -6, "An XML element was malformed",
                on processing instructions that don't begin with "xml". Go figure!

                But good to know for future reference.


                "Ian Kelleigh" <ian_nospam_@freehandsource.com> wrote in message
                news:e4061k$5i6$1@forums.macromedia.com...
                > YES! PERFECT! Thank you very much... spend a greater part of the day
                > trying to get it. Knew I was on the right track but kept losing the XML
                > Declaration part.
                >
                > Thank you again!
                >
                > --
                > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                > remove "_nospam_" to send email
                >
                > Ian Kelleigh
                > ian_nospam_@freehandsource.com
                >
                > "The FreeHand Source"
                > http://www.FreeHandSource.com