Reading an XML file into an Interface

Hi I have a need to be able to select an XML file, and use fields in it to populate an interface.


At the moment I have a simpe interface with a File Upload and a Rule Input of xmlData (Document) which the file upload saves to.

I am then kicking off a process model on submit which runs a script task.

I have activity class parameters for the fields I want and am running the following script on each one

=xpathdocument(pv!xmlFile,"/Document/Fields/Field[@Name='Department']/@Value")
Currently I just get an error on the process model when I debug:
Script Task An error occurred while evaluating expression: =xpathdocument(pv!xmlFile,"/Document/Fields/Field[@Name='Department']/@Value") (Expression evaluation error at function 'xpathdocument': An error occurred while trying to parse the XML stream.) (Data Inputs)

Does anyone know what the error is more specifically?  Am I on the right lines or is there a better way of doing this? 

  Discussion posts and replies are publicly visible

  • Hey David,

    For the XML that you post as example the first code that I sent in my previous answer should work, as I tested it in my local environment.

    In order to speed up your tests you could upload a file to Appian and test it in an expression rule, just past the code that I sent and change the docId, in case it is working in the expression and failing in your process model you need to analyse in detail the steps in your PM.

    Let me know,

    Regards.

    Acacio B.

  • HI Acacio

    Your right - I got the first line of code to work within an expression rule, so Im just going wrong somewhere else in the process model.


    Regarding the second method, that wouldn't work, although the structure of the XML file is slightly different - Ive tried replacing fields with Root and Original Variables - if you could let me know the correct syntax for it that would be great (Ive attached it here)

    <?xml version="1.0" encoding="UTF-8"?>
    <Root>
      <Original Variables>
        <CardholderElement>Carolina Kenny</CardholderElement>
        <Card NumberElement>449450294</Card NumberElement>
      </Original Variables>
      <Scanning/>
      <Queue Info>
        <Company>Parkmill</Company>
      </Queue Info>
    </Root>
    

  • Hi David,

    The xml example that you provided is not a valid xml, the main problem is that you cannot have a XML tag name with spaces, otherwise the second word would be interpreted as an attribute. 

    I edited your example in order to make the XML valid, and from there you can adjust to your process. Please find the valid xml in the code below:

    <?xml version="1.0" encoding="UTF-8"?>
    <Root>
    	<OriginalVariables>
    		<CardholderElement>Carolina Kenny</CardholderElement>
    		<CardNumberElement>449450294</CardNumberElement>
    	</OriginalVariables>
    	<Scanning/>
    	<QueueInfo>
    		<Company>Parkmill</Company>
    	</QueueInfo>
    </Root>

    Below is the code example for you get the company value:

    xpathdocument(
      docId: YOURDOC,
      expression: "Root/QueueInfo/Company/text()" 
    )

    In case these responses were helpful don't forget to mark the question as answered as it can also help other that are facing similar issues.

    Regards,

    Acacio B.