Skip to main content
10-Marble
November 29, 2022
Solved

How to parse xml with custom tag from properties

  • November 29, 2022
  • 3 replies
  • 4139 views

Эй! На данный момент я помещаю XML в свойства созданной вещи. XML выглядит следующим образом:

 

 

<?xml version="1.0" encoding="utf-8"?><n0:MT_ProductionFact xmlns:n0="content" xmlns:prx="content">
<n0:SendTimestamp>content</n0:SendTimestamp>
<n0:ContractProductions>
	<n0:ContractProduction>
		<n0:DeliveryNumber>content</n0:DeliveryNumber>
		<n0:DeliveryItemNumber>content</n0:DeliveryItemNumber>
		<n0:DeliveryMaterialNumber>000000005700000191</n0:DeliveryMaterialNumber>
		<n0:DeliveryMaterialShortName>content</n0:DeliveryMaterialShortName>
		<n0:DeliveryUnits>content</n0:DeliveryUnits>
		<n0:InboundDeliveryDocumentNumber>content</n0:InboundDeliveryDocumentNumber>
		<n0:InboundDeliveryItemNumber>content</n0:InboundDeliveryItemNumber>
		<n0:SupplierBatchCode>content</n0:SupplierBatchCode>
		<n0:DeliveryPlanDate>content</n0:DeliveryPlanDate>
		<n0:DeliveryPlanAmount>content</n0:DeliveryPlanAmount>
		<n0:MaterialDocumentNumber>content</n0:MaterialDocumentNumber>
		<n0:AccountingEntryDate>content</n0:AccountingEntryDate>
		<n0:StockAmountReceived>content</n0:StockAmountReceived>
		<n0:TargetAccountingChangeDate>content</n0:TargetAccountingChangeDate>
	</n0:ContractProduction>
	<n0:ContractProduction>
		<n0:DeliveryNumber>content</n0:DeliveryNumber>
		<n0:DeliveryItemNumber>content</n0:DeliveryItemNumber>
		<n0:DeliveryMaterialNumber>content</n0:DeliveryMaterialNumber>
		<n0:DeliveryMaterialShortName>content</n0:DeliveryMaterialShortName>
		<n0:DeliveryUnits>content</n0:DeliveryUnits>
		<n0:InboundDeliveryDocumentNumber>content</n0:InboundDeliveryDocumentNumber>
		<n0:InboundDeliveryItemNumber>content</n0:InboundDeliveryItemNumber>
		<n0:SupplierBatchCode>content</n0:SupplierBatchCode>
		<n0:DeliveryPlanDate>content</n0:DeliveryPlanDate>
		<n0:DeliveryPlanAmount>content</n0:DeliveryPlanAmount>
		<n0:MaterialDocumentNumber>content</n0:MaterialDocumentNumber>
		<n0:AccountingEntryDate>content</n0:AccountingEntryDate>
		<n0:StockAmountReceived>content</n0:StockAmountReceived>
		<n0:TargetAccountingChangeDate>content</n0:TargetAccountingChangeDate>
	</n0:ContractProduction>
</n0:ContractProductions>
</n0:MT_ProductionFact>

 

 

Но я не могу понять, как анализировать XML и помещать значения в таблицу. Все, что я нашел на форумах, не помогло. Может быть, вы можете мне помочь?

Best answer by Egor.Litvinov

I finally managed to find a solution. On the forum, I found a service for converting XML to JSON, and then I folded the JSON object into an infotable. Thanks for the help @VladimirRosu_116627 

 

// result: JSON
let getJSON = me.ConvertXmlToJSON({
	xml: inputData /* XML */
});

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(Valenta.ProductionPlan)
let infoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
	infoTableName: "InfoTable",
	dataShapeName: "Valenta.ProductionPlan"
});

for (let i = 0; i < getJSON.ContractProductions.ContractProduction.length; i++) {
	infoTable.AddRow({
		DeliveryNumber: getJSON.ContractProductions.ContractProduction[i].DeliveryNumber,
		DeliveryItemNumber: getJSON.ContractProductions.ContractProduction[i].DeliveryItemNumber,
		DeliveryMaterialNumber: getJSON.ContractProductions.ContractProduction[i].DeliveryMaterialNumber,
		DeliveryMaterialShortName: getJSON.ContractProductions.ContractProduction[i].DeliveryMaterialShortName,
		DeliveryUnits: getJSON.ContractProductions.ContractProduction[i].DeliveryUnits,
		InboundDeliveryDocumentNumber: getJSON.ContractProductions.ContractProduction[i].InboundDeliveryDocumentNumber,
		InboundDeliveryItemNumber: getJSON.ContractProductions.ContractProduction[i].InboundDeliveryItemNumber,
		SupplierBatchCode: getJSON.ContractProductions.ContractProduction[i].SupplierBatchCode,
		DeliveryPlanDate: getJSON.ContractProductions.ContractProduction[i].DeliveryPlanDate,
		DeliveryPlanAmount: getJSON.ContractProductions.ContractProduction[i].DeliveryPlanAmount,
		MaterialDocumentNumber: getJSON.ContractProductions.ContractProduction[i].MaterialDocumentNumber,
		AccountingEntryDate: getJSON.ContractProductions.ContractProduction[i].AccountingEntryDate,
		StockAmountReceived: getJSON.ContractProductions.ContractProduction[i].StockAmountReceived,
		TargetAccountingChangeDate: getJSON.ContractProductions.ContractProduction[i].TargetAccountingChangeDate
	});
}

let result = infoTable;

 

 

3 replies

10-Marble
November 29, 2022

If i use this code: 

let xml = me.data;
let newXML = new XML(xml);

I get only "SendTimeStamp"

10-Marble
November 29, 2022

Apparently, the duck method worked...

Now I have discovered that I get only this value in the "data" property...

What can I do wrong? Using the Put method, I send the file that I attached above, but I only get the string "<n0:SendTimestamp xmlns:n0="content">content</n0:SendTimestamp>"

16-Pearl
December 6, 2022

please try steps in below article.

https://www.ptc.com/en/support/article/cs218242

10-Marble
December 6, 2022

It looks like a very old version. Doesn't the platform itself know how to parse an xml file into a table? If he still can't, I don't understand how to get to the data lying in the ContractProduction. I corrected the receipt of the XML file, now I get it in the service as a parameter

Egor.Litvinov10-MarbleAuthorAnswer
10-Marble
December 7, 2022

I finally managed to find a solution. On the forum, I found a service for converting XML to JSON, and then I folded the JSON object into an infotable. Thanks for the help @VladimirRosu_116627 

 

// result: JSON
let getJSON = me.ConvertXmlToJSON({
	xml: inputData /* XML */
});

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(Valenta.ProductionPlan)
let infoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
	infoTableName: "InfoTable",
	dataShapeName: "Valenta.ProductionPlan"
});

for (let i = 0; i < getJSON.ContractProductions.ContractProduction.length; i++) {
	infoTable.AddRow({
		DeliveryNumber: getJSON.ContractProductions.ContractProduction[i].DeliveryNumber,
		DeliveryItemNumber: getJSON.ContractProductions.ContractProduction[i].DeliveryItemNumber,
		DeliveryMaterialNumber: getJSON.ContractProductions.ContractProduction[i].DeliveryMaterialNumber,
		DeliveryMaterialShortName: getJSON.ContractProductions.ContractProduction[i].DeliveryMaterialShortName,
		DeliveryUnits: getJSON.ContractProductions.ContractProduction[i].DeliveryUnits,
		InboundDeliveryDocumentNumber: getJSON.ContractProductions.ContractProduction[i].InboundDeliveryDocumentNumber,
		InboundDeliveryItemNumber: getJSON.ContractProductions.ContractProduction[i].InboundDeliveryItemNumber,
		SupplierBatchCode: getJSON.ContractProductions.ContractProduction[i].SupplierBatchCode,
		DeliveryPlanDate: getJSON.ContractProductions.ContractProduction[i].DeliveryPlanDate,
		DeliveryPlanAmount: getJSON.ContractProductions.ContractProduction[i].DeliveryPlanAmount,
		MaterialDocumentNumber: getJSON.ContractProductions.ContractProduction[i].MaterialDocumentNumber,
		AccountingEntryDate: getJSON.ContractProductions.ContractProduction[i].AccountingEntryDate,
		StockAmountReceived: getJSON.ContractProductions.ContractProduction[i].StockAmountReceived,
		TargetAccountingChangeDate: getJSON.ContractProductions.ContractProduction[i].TargetAccountingChangeDate
	});
}

let result = infoTable;