cancel
Showing results for 
Search instead for 
Did you mean: 

I have a document uploaded to a folder along an XML file.

nimbus1958
Confirmed Champ
Confirmed Champ

I need to parse that XML to add metadata to the document via javascript. I just cannot find a way to extract the value from that XML. Any idea would be welcomed.

Thanks.

Pablo

8 REPLIES 8

angelborroy
Community Manager Community Manager
Community Manager

From Repository JavaScript API, this should work:

var docXml = new XML(document.content);
Hyland Developer Evangelist

Thanks Angel,

I got that far and it works but my problem is retrieving a value within the XML.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<DocumentSet>
<Document>
<FileName>Brief - Lettre_4umqrm82l5ay.pdf</FileName>
<FilePath>\\alfresco\alfresco\MailRoom\Brief - Lettre_4umqrm82l5ay.pdf</FilePath>
<Confidentiality>3-Organisation</Confidentiality>
<Departement>CUAC</Departement>
<Domein___Domaine>DC</Domein___Domaine>
<Info_type>Brief - Lettre</Info_type>
<Medewerker___Collaborateur>Alain Terrieur</Medewerker___Collaborateur>
<Status___Statut>5 - Overgedragen - Transféré</Status___Statut>
</Document>

</DocumentSet>

I just can't seem to get the <Info_type> Value!

Frustrating!

This should work:

docXml.DocumentSet‍.Document.Info_type‍
Hyland Developer Evangelist

Angel, That is what I thought also but ... no luck!

This is taken to its most basic, following your advice and documentation!

var docXml = new XML(document.content);
var infoType = docXml.DocumentSet.Document.Info_type;
document.properties.title = infoType;
document.save();

Drowing in frustration!

Thanks for your help!

angelborroy
Community Manager Community Manager
Community Manager

This works...

var docString = document.content;

if (docString.startsWith("<?xml")) {
     docString = docString.split("\n").slice(1).join("\n")
}

var docXml = new XML(docString);

var infoType = docXml.DocumentSet.Document.Info_type;

logger.log(docXml.Document.Info_type);

... you can change / improve it, as it's a quick PoC.

Hyland Developer Evangelist

Thanks Angel but I have no results. I even tried to change the name of the document but nothing. It is as if the variable was not populated.

I will give it a shot tomorrow on another Alfresco instance in the office and follow your proposition. I’ll let you know the results.

I really appreciate your time and help.

It looks like I included a bad sample.

IMO, the main problem is that you have to omit "DocumentSet" when recovering values from XML.

This doesn't work...

docXml.DocumentSet.Document.Info_type

... but this works

docXml.Document.Info_type
Hyland Developer Evangelist

Thanks Angel, It works!

Big thanks for your help!