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

cancel
Showing results for 
Search instead for 
Did you mean: 
nimbus1958
Active Member II

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

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
angelborroy
Alfresco Employee

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

From Repository JavaScript API, this should work:

var docXml = new XML(document.content);
Hyland Developer Evangelist
nimbus1958
Active Member II

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

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!

angelborroy
Alfresco Employee

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

This should work:

docXml.DocumentSet‍.Document.Info_type‍
Hyland Developer Evangelist
nimbus1958
Active Member II

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

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
Alfresco Employee

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

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
nimbus1958
Active Member II

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

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.

angelborroy
Alfresco Employee

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

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
nimbus1958
Active Member II

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

Thanks Angel, It works!

Big thanks for your help!