ディスカッション
NetSuiteの保存検索やレポートをマスターするための究極のガイドである分析センターを使用して、データの力を最大限に活用しましょう。複雑さを単純化し、組織の真の可能性を解き放ちます。今すぐ分析センターに参加して、新たな高みを目指しましょう!
New AI Community Guidelines. Please review and follow them to ensure AI use stays safe, accurate, and compliant.
Update: Narrative Insights has been restored and is now available.
Narrative Insights is Temporarily Unavailable due to an Infrastructure Issue. Learn how This Impacts Your Account and What to Expect While the Feature is Disabled.
Narrative Insights is Temporarily Unavailable due to an Infrastructure Issue. Learn how This Impacts Your Account and What to Expect While the Feature is Disabled.
nlapiStringToXMLが特殊文字を無視しない
適用
製品: NetSuite 2024.2
シナリオ
nlapiStringToXML APIを使用し、文字列データの値に「<」または「&」が含まれている場合、予期しないエラーが発生します。
解決策
特殊文字「<」および「&」は、XMLの予約文字です。「<」を使用すると、パーサーによって新しい要素の先頭として解釈されるエラーが生成され、「&」は文字エンティティの先頭として解釈されます。これらをテキストとして解析する場合は、CDATAセクション内のすべてがパーサーによって無視されるため、CDATAセクションにラップする必要があります。
予期しないエラーを回避するためのサンプル・コード・スニペットを次に示します。
SuiteScript 1.0:
function getXMLString(request,response){
var dom = '& some values here <';
var domparsed = "<![CDATA[" + dom + "]]>";
nlapiLogExecution('DEBUG','dom',domparsed);
var CDOM = nlapiStringToXML('<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><EqtResp><val>'+ domparsed +'</val></EqtResp>');
var node = nlapiSelectNode(CDOM, "//*[name()='EqtResp']");
nlapiLogExecution('DEBUG', 'test', 'select value='+ nlapiSelectValue(node, "//*[name()='val']"));
SuiteScript 2.0:
function getXMLString(context){
var dom = '& some values here <';
var domparsed = "<![CDATA[" + dom + "]]>";
log.debug('dom',domparsed);
var CDOM = Parser.fromtString({text: '<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><EqtResp><val>'+ domparsed +'</val></EqtResp>'})
var node = XPath.select({
node: CDOM,
xpath: "//*[name()='EqtResp']"
})
log.debug('TEST', 'select value='+ nlapiSelectValue(node, "//*[name()='val']"));
タグ付けされた:
0