Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.2K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Suppress from a list of XMLElements those with a specific pattern

Posted 11 years ago

Hello,

I have a list of XMLElements. I would like to suppress those which have a name different from a specific name for example "YO". Here an example :

XMLtest = {XMLElement["YO", {}, 2],XMLElement["BA", {}, 2]}

Here my code

TRI = DeleteCases[XMLtest, XMLElement[_, _, _] /; XMLElement[_, _, _]<>XMLElement["YO", _, _], Infinity]

Consequently, i would like to obtain a list with only the XMLElement which has the name "YO".

I'm sorry if my question is quiet simple. I have started using mathematica not a long time ago.

Thanks a lot for your help.

POSTED BY: B B
5 Replies
Posted 11 years ago

I simply my last question. Thank you in advance for your help

My question was : May you help me to modify this code in order I can add several conditions on the XMLElements that I want to keep in my XMLObjects. ? I need to keep now too types of XMLElements : XMLELements called "YO" and XMLElements called "TI".

POSTED BY: B B
Posted 11 years ago

Thank you for your help and code proposal. The way you handle the nested XMLElements is perfect for me because it suppresses the unnecessary levels that I had before. As i wanted in this example only kept the XMLElements called "YO", I added the function "Except" and it works good.

XMLtest = Block[{XMLElement}, XMLElement[Except@"YO", , {content_XMLElement}] := content; XMLElement[Except@"YO", , ] := Sequence[]; XMLtest]

I need to keep now too types of XMLElements : XMLELements called "YO" and XMLElements called "TI". May you help me to modify this code in order I can add several conditions on the XMLElements that I want to keep in my XMLObjects. ?

Thank you for your help.

POSTED BY: B B
Posted 11 years ago
POSTED BY: Kuba Podkalicki
Posted 11 years ago
POSTED BY: B B
Posted 11 years ago
POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard