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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krusk
    Mini Mivite

    • Oct 2015
    • 29

    #1

    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.
  • Bruce - PhosphorMedia
    Developer Partner











    • Mar 2006
    • 11256

    #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

    • krusk
      Mini Mivite

      • Oct 2015
      • 29

      #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

      • krusk
        Mini Mivite

        • Oct 2015
        • 29

        #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:



        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

        • Kent Multer
          Mega Mivite









          • Mar 2006
          • 3252

          #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

          • Bruce - PhosphorMedia
            Developer Partner











            • Mar 2006
            • 11256

            #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

            • dcarver
              Director of Software Dev.




              • May 2013
              • 400

              #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

              • krusk
                Mini Mivite

                • Oct 2015
                • 29

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

                Thanks David

                Comment

                • krusk
                  Mini Mivite

                  • Oct 2015
                  • 29

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

                  Thanks Kent. This is very helpful for debugging.

                  Comment

                  • krusk
                    Mini Mivite

                    • Oct 2015
                    • 29

                    #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