5

So i just started using Phpstorm and I am trying to 'correct' my code so there are no errors from the IDE. I have the following method below and all my xml tags are highlighted with the 'Unknown HTML tag'

What is the best way to correct this?

private function generate_qbxml_CustomerAddRq($requestID=0){
                /** requestID is used when multiple requests are called in order to match the request to the response.
                    requestID's should be incremented as they are called. Currently not implimented. **/
                $qbxml  = '';
                $qbxml .= '<?xml version="1.0" encoding="utf-8"?>';
                $qbxml .= '<?qbxml version="2.0"?>';
                $qbxml .= '<QBXML>';
                $qbxml .=   '<QBXMLMsgsRq onError="stopOnError">';
                $qbxml .=       '<CustomerAddRq requestID="'.$requestID.'">';
                $qbxml .=           '<CustomerAdd>';
                $qbxml .=               '<Name>'.$this->Name.'</Name>'; //Name is a mandatory field. Add a check for this.
                /** For all optional values add a check so that xml tags are not sent in request if value is blank**/
                $qbxml .=               '<CompanyName>'.$this->CompanyName.'</CompanyName>';               
                $qbxml .=               '<FirstName>'.$this->FirstName.'</FirstName>';
                $qbxml .=               '<LastName>'.$this->LastName.'</LastName>';
                $qbxml .=               '<BillAddress>';
                $qbxml .=                   '<Addr1>'.$this->BillAddress->get_Addr1().'</Addr1>';
                $qbxml .=                   '<Addr2>'.$this->BillAddress->get_Addr2().'</Addr2>';
                $qbxml .=                   '<City>'.$this->BillAddress->get_City().'</City>';
                $qbxml .=                   '<State>'.$this->BillAddress->get_State().'</State>';
                $qbxml .=                   '<PostalCode>'.$this->BillAddress->get_PostalCode().'</PostalCode>';                                
                $qbxml .=                   '<Country>'.$this->BillAddress->get_Country().'</Country> ';                               
                $qbxml .=               '</BillAddress>';
                $qbxml .=               '<ShipAddress>';
                $qbxml .=                   '<Addr1>'.$this->ShipAddress->get_Addr1().'</Addr1>';
                $qbxml .=                   '<Addr2>'.$this->ShipAddress->get_Addr2().'</Addr2>';
                $qbxml .=                   '<City>'.$this->ShipAddress->get_City().'</City>';
                $qbxml .=                   '<State>'.$this->ShipAddress->get_State().'</State>';
                $qbxml .=                   '<PostalCode>'.$this->ShipAddress->get_PostalCode().'</PostalCode>';                                
                $qbxml .=                   '<Country>'.$this->ShipAddress->get_Country().'</Country> ';                               
                $qbxml .=               '</ShipAddress>';
                $qbxml .=               '<Phone>'.$this->Phone.'</Phone>';
                $qbxml .=               '<AltPhone>'.$this->AltPhone.'</AltPhone> ';
                $qbxml .=               '<Fax>'.$this->Fax.'</Fax> ';
                $qbxml .=               '<Email>'.$this->Email.'</Email> ';
                //$qbxml .=               '<JobDesc>Ob2</JobDesc>';
                $qbxml .=           '</CustomerAdd>';                
                $qbxml .=       '</CustomerAddRq>';
                $qbxml .=   '</QBXMLMsgsRq>';
                $qbxml .= '</QBXML>';

                return $qbxml;
            }
Chris
  • 2,166
  • 1
  • 24
  • 37

2 Answers2

15

Ok I figured it out myself.

Alt+Enter then select Add <'tag'> to custom HTML tags.

Similar to how you handle words that come up as typos.

Chris
  • 2,166
  • 1
  • 24
  • 37
2

You can mark the string/var as a 'language injection':

  1. Place the caret inside the string literal, tag, or attribute, in which you want to inject a language and press Alt+Enter (or use the intention action icon Intention action icon).
  2. Select Inject language or reference and choose the language you want to inject.

https://www.jetbrains.com/help/phpstorm/using-language-injections.html

The result looking like this:

$xmlString = /** @lang XML */
'<?xml version="1.0" encoding="utf-8" ?>';
mr12086
  • 1,137
  • 13
  • 29
  • This is a better solution than my original answer. Only took 7+ years for someone to respond ;). I have switched this to the correct answer. Thank you. (Note: I stopped using php storm a long time ago.) – Chris Feb 03 '22 at 01:08