6 Replies Latest reply on Jan 30, 2009 11:28 AM by bitwyse

    XML Help please. . .

    bitwyse Level 1
      Hi all,

      I am looking for some basic XML help. I have the following xml file that I read in ( that I can control the contents ). I want to read it in, take some user input and change the contents of the xml file with a replace.

      When the user enters a value of say 123 I want to replace XXX with 123. For some reason I can not get this to work. I"m a total XML dork. Here is the code I am using today without success. . .

      What happens, is the XMLNode gets another element named aPath with my value. I have tried various combinations of code to get this to work and either get errors of null values or adding an element. Ugh. This should be simple and I'm sure it is. I just can't figure it out. Can you help? I can change the xml file to be what ever I want. So if that is the problem let me know.

      Thanks,

      STeveR
        • 1. Re: XML Help please. . .
          Level 1
          The text is a child of apath if it were a property you could access it like so

          path.apath.@value

          With regard to the string you would use regular expression to search and replace
          • 2. Re: XML Help please. . .
            Level 7

            "bitwyse" <webforumsuser@macromedia.com> wrote in message
            news:glv84l$nc4$1@forums.macromedia.com...
            > Hi all,
            >
            > I am looking for some basic XML help. I have the following xml file that
            > I
            > read in ( that I can control the contents ). I want to read it in, take
            > some
            > user input and change the contents of the xml file with a replace.
            >
            > When the user enters a value of say 123 I want to replace XXX with 123.
            > For
            > some reason I can not get this to work. I"m a total XML dork. Here is
            > the
            > code I am using today without success. . .
            >
            > What happens, is the XMLNode gets another element named aPath with my
            > value.
            > I have tried various combinations of code to get this to work and either
            > get
            > errors of null values or adding an element. Ugh. This should be simple
            > and
            > I'm sure it is. I just can't figure it out. Can you help? I can change
            > the
            > xml file to be what ever I want. So if that is the problem let me know.
            >
            > Thanks,
            >
            > STeveR
            >
            > ?xml version="1.0" encoding="utf-8"?>
            > <SourcePaths>
            > <Path>
            > <aPath>m:scan\XXX\reserve studyz</aPath>
            > </Path>
            > <Path>
            > <aPath>m:scan\XXX\reserve study</aPath>
            > </Path>
            > <Path>
            > <aPath>m:scan\XXX\2008 scanning\minutes</aPath>
            > </Path>
            > <Path>
            > <aPath>m:scan\XXX\2008 scanning\insurance policy</aPath>
            > </Path>
            > <Path>
            > <aPath>m:scan\XXX\2009 scanning\insurance policy</aPath>
            > </Path>
            > <Path>
            > <aPath>m:scan\XXX\2008 scanning\budget</aPath>
            > </Path>
            > <Path>
            > <aPath>o:\supporting docs\2008 audit information\properties\XXX</aPath>
            > </Path>
            > </SourcePaths>
            >
            > private function onComboBoxChange( event : CreateAuditCDEvent ) : void
            > {
            > var anXMLNode : XML;
            > var propertyNumber : String = event.selectedProperty;
            >
            > for each( anXMLNode in gListOfSourcePaths )
            > {
            > anXMLNode.aPath[0] = anXMLNode..aPath.toString().replace( "XXX",
            > propertyNumber );

            This expression: anXMLNode..aPath returns lots and lots of XML nodes.
            That's probably part of your problem.

            Check this out:
            http://dispatchevent.org/roger/as3-e4x-rundown/

            Also check out the text() property of the XML object.

            HTH;

            Amy


            • 3. Re: XML Help please. . .
              Gregory Lafrance Level 6
              This code should get you started:
              • 4. Re: XML Help please. . .
                bitwyse Level 1
                Thank you all very much for you advice!!!

                Greg, your code was spot on. Can you explain what I was doing wrong. I see your code and get what your doing, It just seems to me that mine should have worked as well. Obviously I don't have a great handle on managing XML.

                Anyway you can dissect the code a bit for me and others perhaps struggling with the same issues???

                Thanks again for all your help!!! You rock as always.
                • 5. Re: XML Help please. . .
                  Gregory Lafrance Level 6
                  I'm not exactly sure, but if your gListOfSourcePaths was an XMLLIstCollection or maybe XMLList, I think it may have to do with your accessing the data as follows:

                  anXMLNode.aPath[0] = anXMLNode..aPath ...

                  I'm no E4X and XML expert, but I usually just try to solve the problem somehow. I think I tried your syntax, and it didn't work, so I just iterated over the elements in the XMLListCollection and did the replace as in my code.

                  Using the RegExp may have helped as well.

                  Sorry I can't be of more help, but like I said, when code doesn't work, I just start to massage it in different ways, and hope it responds well. :-)
                  • 6. Re: XML Help please. . .
                    bitwyse Level 1
                    I hear you. In fact I was using an XMLListCollection as you thought. I too was trying different things but just never got to where you did.

                    Thanks again for the help!!!!