106
Views
3
Comments
Parse Complex XML - How can i read a node attribute value?
Application Type
Traditional Web

Good afternoon everyone,


i am in need of some help. I have only worked with simple xml files, like the one in [Image 1]. 

[Image 1]


Now it was given to me this file [Image 2]:

[Image 2]

 

I need to extract the following fields: SAMPLETYPE, SAMPLEIDENT, ANALYTNAME, NUMERICVALUE and ROUNDEDVALUE. From what i can understand, the data that i need to extract is saved inside the attributes.

I started to do what i normally do: read the xml file, select all the SAMPLE nodes and loop through them to get the needed information.

Now, here is the problem: after selecting the current SAMPLE node, i use the action XmlElement_SelectSingleNode (Select_SampleType) to get value of the attribute SAMPLETYPE.

When i test the action, it returns a "Object reference not set to an instance of an object.". After doing some research, i suspect that the problem is what i am trying to read, because its a "attribute" of the node SAMPLE and not the value that the node holds.


Can the action provided by OutSystems help in obtaining the data that i need? If soo, can someone provide me with a mock up action/example? 


P.S: Can this be more easily done by a forge component? 

Some of the forum posts that i have read indicated this forge component as a solution:

https://www.outsystems.com/forge/component-overview/153/xml-records

Can it help in what i need?

Thanks for your time.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Luís Amaro ,

as you say, you want attribute values.

I see you are already using the xml extension, you can find in there actions that get and set attributes, you need to use those instead of SelectSingleNode.  I would guess XmlElement_GetAttributeValue will do it for you.


Dorine

UserImage.jpg
Luís Amaro

Thanks! In fact, i did more research and eventually found the action that i needed has the GetAttributeValue.

Now i have other question: I use the action XmlNodeList_Item to select a specific SAMPLE node. Now, for the current SAMPLE i need to select the ANALYTE nodes that are inside the SCHEME node, loop through them, and save the data that i need.

I tried using the XmlDocument_SelectNodes like this, but it is returning a "Object reference not set to an instance of an object." error. i think i am using the wrong action. 

What action should i use? I will continue to search, but if you could lend a hand i will appreciate it!

2021-09-06 15-09-53
Dorine Boudry
 
MVP

can you share a sample oml, I'll have a look.

I don't know by heart and don't have time to set oml up myself.

But at first glance : I don't see what SAMPLEBIOFIELD is doing there, SCHEME is direct child of SAMPLE

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.