XML Parsing Using Ui Path - Different Possible Approach

Hello All,

I am facing one issue in while trying to extract Data From a XML file. Exception is coming as “The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name.”

My Requirement is to get Nodes text of TNumber Node With TicketedPCC Attribute as “YYYY”. I have used xmlDocument.Elements but facing some issue as I am having one node with having “:” in the node name. If there is any better way capture, then please suggest.

I have attached my workflow for reference. Thank you.

TestProcess - Copy.zip (19.5 KB)

@loginerror @Yoichi @Palaniyappan

Hi,

In this case, we need to handle xml namespace.
Hope the following sample helps you.

TestProcess - CopyV2.zip (4.6 KB)

Regards,

@Ashish6541

as mentioned by @Yoichi the namespace is to handle.

as an alternate have a look here for an approach with XPath, Retrieval config etc.

1 Like

Hello @Yoichi - First of all, Thanks for the response, Very Helpful.

I was trying to understand this namespace thing, and concluded that this will only work when we have unique tag name. In any xml file where ever there is a Node TNumber, It will pick data. But I can see there is a risk of using this, that is because TNumber can present inside more two different Parent Node. For example There are TNumber nodes present in one parent node TNode1 and TNode2. In this case we need TNumber data present inside TNode2. But if we try using the solution it will provide me output of both the parent node.

  • Can we solve the above problem using Namespace?
  • Can you provide me some useful links where I can learn more things on the Namespace.

Adding my other XML File: input1.xml (885 Bytes)

Hi,

Can we solve the above problem using Namespace?

Yes, can you try as the following image? First, we need to get TNode2 (PNRINFO_YYY), then get TNumber from it.

Can you provide me some useful links where I can learn more things on the Namespace.

Unfortunately, I’m not familiar with good xml learning site in English because my native language is not English. However, as xml is mature technology, there are many good site in the internet. We’ll be able to find it by search engine easily, I think.

Regards,

1 Like

@Ashish6541
have a look here:



2 Likes

Thanks @Yoichi. Just saw your comment with the solution, Thanks for that.
Before seeing your comment I was trying this and solved. I can see I have used the same approach what you mentioned in the comment.

But I need one thing to understand. We are using xns variable that is storing the default name space. We are using that for each time we are looking for Descendants. Can I know, what it does actually?

deserilizedXML.Descendants(xns+“JXTSTranRequest”)

I have printed that in the Output and it was printed as JXTS.

Added File With Solution for any learner’s references: TestProcess - V3.zip (5.3 KB)

@Yoichi - Please help me understand this.

@ppr I went though your link. I am bit confused in that link. Can you use my existing xml file and provide me sample code to understand this.
input1.xml (1.1 KB)

I have gone through this links (For XML Details) what you shared. It is helpful. Thank you.
@ppr - Can you please take a look?

[quote=“Ashish6541, post:1, topic:270280”]
I am facing one issue in while trying to extract Data From a XML file. Exception is coming as “The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name.”

@acaciomelo @AndrewHall @badita - Please help me with this or tag anyone who can help me.

I have added two sample Example, where I have used Element,

  • File 01 - Working As there is no “:” in the node name : TestXML_01.zip (14.5 KB)
  • File 02 - Not Working as there is “:” in the node name : TestXML_02.zip (5.1 KB)

Please advise.

@Ashish6541

  • TestXML_01.zip - SampleXML.xml - no name spaces - can be processed directly, adresing the elements by its name

  • testXML_02.zip:

    • input1.xml . has defined namesspaces - can be processed as described above by using the namespaces within the element name referencing
    • input1 -Copy.xml - is a fragment with prefix in the name but no namespace definition of the used prefix - can be tricked with a dummy namespace

Okay Thank You!

Thanks @ppr @Yoichi for your inputs to understand this.

I am adding the example xaml for anyone’s help and marking it as Solution.

  • No name spaces - can be processed directly by addressing the elements by its name : TestXML_01.zip (14.5 KB)
  • Has defined names spaces : TestXML_02.zip (5.1 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.