Hello,
As a result of many operations, i get the below XML:
i need to insert the below line and close it off at the end…
blas blah blah…
should looks similar to this:
How can achieve this?
just adding it as a root attribute does not work…
Thank you in advance
DD
Hi @xewonder , can you share the JSON output of your final Function node as well as the line you’d like to insert as text rather than a screenshot? I am not super familiar with XML but am happy to give it a try on my side
thank you so much
Blockquote
[
{
“”: “<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n\n \n \n weqrewrewqr\n GR\n 0\n \n \n 9982\n GR\n 0\n Som.\n \n \n \n Μάρκου \n \n 11\n Αθήνα\n \n \n \n RNT\n 1587\n GR\n \n \n \n \n 1\n 65.00000000\n 0\n 0\n \n icls:classificationtype ok</icls:classificationtype>\n icls:classificationCategory/ \n \n icls:amount/ \n icls:id/ \n \n \n \n \n \n 2\n 2.00000000\n 0\n 0\n \n icls:classificationtype ok</icls:classificationtype>\n icls:classificationCategory/ \n \n icls:amount/ \n icls:id/ \n \n \n \n”
}
]
this has to go between “?xml version” and “invoice”
(sorry… can’t seem to be able to paste the code)
should look like this:
“InvoicesDoc” should then be closed at the very end…
Sorry… just found out how to insert the text…
output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<invoice>
<issuer>
<vatNumber>weqrewrewqr</vatNumber>
<country>GR</country>
<branch>0</branch>
</issuer>
<counterpart>
<vatNumber>99xxxxxxx</vatNumber>
<country>GR</country>
<branch>0</branch>
<name>Soxxxxxx.</name>
<address>
<street>Μάρκοxxxxxxx</street>
<number/>
<postalcode>11xxxxx</postalcode>
<city>Αθήνα</city>
</address>
</counterpart>
<invoiceHeader>
<series>RNT</series>
<aa>1587</aa>
<test>GR</test>
</invoiceHeader>
<invoiceDetails>
<lineNumber>1</lineNumber>
<netValue>65.00000000</netValue>
<vatCategory>0</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationtype>ok</icls:classificationtype>
<icls:classificationCategory/>
<propertyName/>
<icls:amount/>
<icls:id/>
</incomeClassification>
</invoiceDetails>
<invoiceDetails>
<lineNumber>2</lineNumber>
<netValue>2.00000000</netValue>
<vatCategory>0</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationtype>ok</icls:classificationtype>
<icls:classificationCategory/>
<propertyName/>
<icls:amount/>
<icls:id/>
</incomeClassification>
</invoiceDetails>
</invoice>
the part to be inserted…
<InvoicesDoc xmlns="http://www.aade.gr/myDATA/invoice/v1.0" xsi:schemaLocation="http://www.aade.gr/myDATA/invoice/v1.0 schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ic="https://www.aade.gr/myDATA/incomeClassificaton/v1.0">
how it should look at the end:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvoicesDoc xmlns="http://www.aade.gr/myDATA/invoice/v1.0" xsi:schemaLocation="http://www.aade.gr/myDATA/invoice/v1.0 schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ic="https://www.aade.gr/myDATA/incomeClassificaton/v1.0">
<invoice>
<issuer>
<vatNumber>weqrewrewqr</vatNumber>
<country>GR</country>
<branch>0</branch>
</issuer>
<counterpart>
<vatNumber>998xxxxx</vatNumber>
<country>GR</country>
<branch>0</branch>
<name>Soxxxxxx.</name>
<address>
<street>Μάρκοxxxxx</street>
<number/>
<postalcode>11xxxx</postalcode>
<city>Αθήνα</city>
</address>
</counterpart>
<invoiceHeader>
<series>RNT</series>
<aa>1587</aa>
<test>GR</test>
</invoiceHeader>
<invoiceDetails>
<lineNumber>1</lineNumber>
<netValue>65.00000000</netValue>
<vatCategory>0</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationtype>ok</icls:classificationtype>
<icls:classificationCategory/>
<propertyName/>
<icls:amount/>
<icls:id/>
</incomeClassification>
</invoiceDetails>
<invoiceDetails>
<lineNumber>2</lineNumber>
<netValue>2.00000000</netValue>
<vatCategory>0</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationtype>ok</icls:classificationtype>
<icls:classificationCategory/>
<propertyName/>
<icls:amount/>
<icls:id/>
</incomeClassification>
</invoiceDetails>
</invoice>
</InvoicesDoc>
Hi @xewonder , if this line will always come after the first line in your XML String, the below approach should work:
You can simply copy & paste the Insert Line node from the workflow above into your n8n canvas by first selecting it, then using Ctrl+C (to copy) and Ctrl+V (to paste).
This is the result:
This node is a Function Item node running custom JavaScript (as I couldn’t find a suitable built-in transformation in the XML node itself). It uses three different methods to achieve this:
.split() to split up the XML string into individual lines
.splice() to add a new line after the first one
.join() to convert our array of lines back into a single string
Hope this helps!
Try the Function Item node instead of the Function node.
ok…
I had to use a “set” and assign “data” to it
now i have another problem…
“data” is causing me a problem when trying to send the HTTP POST request.
how can i fix that?
Thank you
DD
Jon
September 9, 2022, 8:58am
10
Hey @xewonder ,
Can you share the XML? The error seems to suggest it is not valid.
it’s kind of strange as I am only sending the XML?
there is no “data” there…
looks ok to me…
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvoicesDoc xmlns="http://www.aade.gr/myDATA/invoice/v1.0" xsi:schemaLocation="http://www.aade.gr/myDATA/invoice/v1.0 schema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ic="https://www.aade.gr/myDATA/incomeClassificaton/v1.0">
<invoice>
<issuer>
<vatNumber>weqrewrewqr</vatNumber>
<country>GR</country>
<branch>0</branch>
</issuer>
<counterpart>
<vatNumber>9xxxxxx</vatNumber>
<country>GR</country>
<branch>0</branch>
<name>Soxxxxxxx</name>
<address>
<street>Μάxxxxxxx</street>
<number/>
<postalcode>11xxxxxx</postalcode>
<city>Αθήνα</city>
</address>
</counterpart>
<invoiceHeader>
<series>RNT</series>
<aa>1587</aa>
<test>GR</test>
</invoiceHeader>
<invoiceDetails>
<lineNumber>1</lineNumber>
<netValue>65.00000000</netValue>
<vatCategory>0</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationtype>ok</icls:classificationtype>
<icls:classificationCategory/>
<propertyName/>
<icls:amount/>
<icls:id/>
</incomeClassification>
</invoiceDetails>
<invoiceDetails>
<lineNumber>2</lineNumber>
<netValue>2.00000000</netValue>
<vatCategory>0</vatCategory>
<vatAmount>0</vatAmount>
<incomeClassification>
<icls:classificationtype>ok</icls:classificationtype>
<icls:classificationCategory/>
<propertyName/>
<icls:amount/>
<icls:id/>
</incomeClassification>
</invoiceDetails>
</invoice>
</InvoicesDoc>
sorry…
let me check with proper settings for my post request
Mikhail
January 30, 2023, 8:53am
14
Hi @MutedJam !
With the new code node, there is an error:
Could you tell me what to do to fix it?
My problem was solved here:
Hi!
I have this structure in the XML at the top:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Ads>
<Ad>
</Ad>
I need to get this:
<?xml version="1.0" encoding="UTF-8"?>
<Ads formatVersion="3" target="Avito.ru">
<Ad>
</Ad>
i.e., I need to
remove: " standalone=“yes”? " and
add " formatVersion=“3” target=“Avito.ru ” " in Ads
Please help me. How to do it?
Thank you very much!
Please share the workflow
Informat…
BramKn
January 30, 2023, 9:39am
15
I guess this is from this solved topic?
Hi!
I have this structure in the XML at the top:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Ads>
<Ad>
</Ad>
I need to get this:
<?xml version="1.0" encoding="UTF-8"?>
<Ads formatVersion="3" target="Avito.ru">
<Ad>
</Ad>
i.e., I need to
remove: " standalone=“yes”? " and
add " formatVersion=“3” target=“Avito.ru ” " in Ads
Please help me. How to do it?
Thank you very much!
Please share the workflow
Informat…
Mikhail
January 30, 2023, 10:42am
16
Hi @BramKn ! Yes, you’re right. I was trying to solve the problem.
BramKn
January 30, 2023, 10:45am
17
@Mikhail make sure to stick to one topic. If Tom didn’t see the other topic he could have spent time to try and help you, where it was already solved.
Mikhail
January 30, 2023, 10:49am
18
ОК. I edited my post above and added a link