Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attribute reader #7

Open
marzobryant90 opened this issue Sep 25, 2023 · 1 comment
Open

attribute reader #7

marzobryant90 opened this issue Sep 25, 2023 · 1 comment

Comments

@marzobryant90
Copy link

Hi @JenniferSimonds,
is it possible to use your apex-xpath for reading properties like "Name1/Name2/@Attribute" ?

I would like to read the Code property here.

<ISTATCode Code="20594/07" Type="C">Fabbricazione di prodotti chimici vari per uso industriale (inclusi i preparati antidetonanti e antigelo)</ISTATCode>

How can I accomplish it?

Thanks,
Claudio

@JenniferSimonds
Copy link
Owner

Hi, Claudio.

To get the value of the attribute, I would find the element first, then use XmlNode.getAttribute. Something like this:

String xml =
'<ISTATCode Code="20594/07" Type="C">Fabbricazione di prodotti chimici vari per uso industriale (inclusi i preparati antidetonanti e antigelo)</ISTATCode>';
XPath xp = new XPath(xml);
//List<Dom.XmlNode> nodes = xp.find('/ISTATCode');
//Dom.XmlNode node = nodes[0];

Dom.XmlNode node = xp.findFirst('/ISTATCode');
System.debug('getName = ' + node.getName());
System.debug('getText = ' + node.getText());
System.debug('getAttribute = ' + node.getAttribute('Code', null));
Screenshot-xpath1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants