Announcement

Collapse
No announcement yet.

MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.

    Hi all,

    I need to send simple nested XML to a vendor, but am getting the following error:

    INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.

    I am loading the POST call in my Invoice Page Template using MVT as follows:

    HTML Code:
    <mvt:assign name="l.xml" value="'<?xml version=\"1.0\" encoding=\"utf-8\"?>' $ asciichar(10)" />
    <mvt:assign name="l.xml" value="l.xml $ '<OrderID>' $ l.settings:order:id $ '</OrderID>' $ asciichar(10) "/>
    <mvt:foreach iterator="item" array="order:groups">
      <mvt:assign name="l.xml" value="l.xml $ '<Item>' $ asciichar(10) "/>
      <mvt:assign name="l.xml" value="l.xml $ '<ItemID>' $ l.settings:item:code $ '</ItemID>' $ asciichar(10) "/>
        <mvt:assign name="l.xml" value="l.xml $ '</Item>' $ asciichar(10) "/>
    </mvt:foreach>
    
    <mvt:call action="'http://myvendorsapi.net/orders'" method="'POST'" fields="XML">
        <mvt:eval expr="s.callvalue" />
    </mvt:call>
    With multiple items, I am expecting it to send XML like this:

    <post>
    <orderaddr>
    555 My Address
    </orderaddr>
    <orderemail>
    [email protected]
    </orderemail>
    <item>
    <ordercode>
    RSC1
    </ordercode>
    </item>
    <item>
    <ordercode>
    RSC2
    </ordercode>
    </item>
    </post>


    Please assist, I have hit a wall.

    K.

    #2
    Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

    You might need to wrap the email with CDATA (and all other data from external sources like names, addresses, etc.

    <![CDATA[[email protected]]]>
    Bruce Golub
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

      Thanks Bruce,

      I've tried it without the email and it still fails. Any clues?

      K.

      Comment


        #4
        Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

        Essentially, I am trying to resolve the same issue you were helping me with here:

        http://extranet.miva.com/forums/show...750#post438750

        In that I need the solution to be in MVT.

        Thanks!

        K.

        Originally posted by Bruce - PhosphorMedia View Post
        You might need to wrap the email with CDATA (and all other data from external sources like names, addresses, etc.

        <![CDATA[[email protected]]]>

        Comment


          #5
          Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

          You can put an mvt:eval on the template, so that it will display the complete XML text on the page. That will give you a chance to look at it, and see exactly what XML your code is creating. Be sure to use an encodeentities() call, something like:
          Code:
          <mvt:eval expr="'<p> XML code: <br/> ' $ encodeentities(l.xml) $ ' </p>'" />
          -- otherwise you won't see the code on your page.

          Also, you can change the action URL, so that the XML request is made to a small test script running on your own site. This script can save the received XML into a text file: that gives you another way to verify what your code is creating.

          Also, I would try using a global variable g.xml, or a settings variable l.settings:xml, instead of the straight local variable l.xml.

          HTH --
          Last edited by Kent Multer; 12-01-15, 10:28 AM.
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

            i think you also want XML has the method for the post...
            Bruce Golub
            Phosphor Media - "Your Success is our Business"

            Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
            phosphormedia.com

            Comment


              #7
              Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

              Originally posted by krusk View Post
              Hi all,

              I need to send simple nested XML to a vendor, but am getting the following error:

              INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.

              I am loading the POST call in my Invoice Page Template using MVT as follows:

              HTML Code:
              <mvt:assign name="l.xml" value="'<?xml version=\"1.0\" encoding=\"utf-8\"?>' $ asciichar(10)" />
              <mvt:assign name="l.xml" value="l.xml $ '<OrderID>' $ l.settings:order:id $ '</OrderID>' $ asciichar(10) "/>
              <mvt:foreach iterator="item" array="order:groups">
                <mvt:assign name="l.xml" value="l.xml $ '<Item>' $ asciichar(10) "/>
                <mvt:assign name="l.xml" value="l.xml $ '<ItemID>' $ l.settings:item:code $ '</ItemID>' $ asciichar(10) "/>
                  <mvt:assign name="l.xml" value="l.xml $ '</Item>' $ asciichar(10) "/>
              </mvt:foreach>
              
              <mvt:call action="'http://myvendorsapi.net/orders'" method="'POST'" fields="XML">
                  <mvt:eval expr="s.callvalue" />
              </mvt:call>
              With multiple items, I am expecting it to send XML like this:

              <post>
              <orderaddr>
              555 My Address
              </orderaddr>
              <orderemail>
              [email protected]
              </orderemail>
              <item>
              <ordercode>
              RSC1
              </ordercode>
              </item>
              <item>
              <ordercode>
              RSC2
              </ordercode>
              </item>
              </post>


              Please assist, I have hit a wall.

              K.
              Hi krusk,


              The issue is you need to have the fields parameter value wrapped in single quotes, otherwise it evaluates the current l.xml value as the variable name which returns blank. You should also prefix the fields value with "l." for "l.xml" which will give an ever so slight performance increase.


              Let me know if you have any other questions.


              Thanks
              David Carver
              Miva, Inc. | Software Developer

              Comment


                #8
                Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

                Thanks David

                Comment


                  #9
                  Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

                  Thanks Kent. This is very helpful for debugging.

                  Comment


                    #10
                    Re: MVT CALL - INVALID_CHARACTER_ERR: An invalid or illegal XML character is specifie

                    Thanks Bruce. Using that allows me to declare the desired content-type.

                    Comment

                    Working...
                    X