Skip to main content
edited for clarity
Source Link
WReach
  • 69.3k
  • 4
  • 165
  • 272

I want filter information from a .xml file, the general xml rule isfrom elements that look like this:

XMLElement["div", {"class" -> "art_title linkable"},
  {XMLElement["a", 
 {"shape" -> "rect", "class" -> "ref nowrap", 
 "href" -> "XXXX"},
    {"name"} ]}]

so I use the following code, it will word good, to filter out the text from the a element:

Cases[data, 
 XMLElement[
    "div", {"class" -> "art_title linkable"}, {XMLElement[
      "a", {___}, {papername_}]}] :> {papername}, {0, Infinity}]; 

(* {{"name"}} *)

But I found there arethis does not work if the content of the special condition,a element is more complicated:

XMLElement["div", {"class" -> "art_title linkable"}, {XMLElement[
   "a"{XMLElement["a", {"shape" -> "rect", "class" -> "ref nowrap", 
    "href" -> "XXXX"}, {XMLElement[
     "b"{XMLElement["b", {}, {"namepart1"}], 
    "namepart2"} ]}]

The name of the special form can't use... which gives the code, so I hope someone can help me, if there is a methodresult {}.

How can get the name forI extract just the spectial condtion.text "namepart1namepart2 in this second case?

I want filter information from a .xml file, the general xml rule is

XMLElement["div", {"class" -> "art_title linkable"}, {XMLElement["a", 
 {"shape" -> "rect", "class" -> "ref nowrap", 
 "href" -> "XXXX"}, {"name"}]}]

so I use the following code, it will word good,

Cases[data, 
 XMLElement[
    "div", {"class" -> "art_title linkable"}, {XMLElement[
      "a", {___}, {papername_}]}] :> {papername}, {0, Infinity}];

But I found there are special condition,

XMLElement["div", {"class" -> "art_title linkable"}, {XMLElement[
   "a", {"shape" -> "rect", "class" -> "ref nowrap", 
    "href" -> "XXXX"}, {XMLElement[
     "b", {}, {"namepart1"}], 
    "namepart2"}]}]

The name of the special form can't use the code, so I hope someone can help me, if there is a method can get the name for the spectial condtion.

I want filter information from a .xml file, from elements that look like this:

XMLElement["div", {"class" -> "art_title linkable"},
  {XMLElement["a", {"shape" -> "rect", "class" -> "ref nowrap", "href" -> "XXXX"},
    {"name"} ]}]

I use the following code to filter out the text from the a element:

Cases[data, 
 XMLElement[
    "div", {"class" -> "art_title linkable"}, {XMLElement[
      "a", {___}, {papername_}]}] :> {papername}, {0, Infinity}]; 

(* {{"name"}} *)

But this does not work if the content of the a element is more complicated:

XMLElement["div", {"class" -> "art_title linkable"},
  {XMLElement["a", {"shape" -> "rect", "class" -> "ref nowrap", "href" -> "XXXX"},
    {XMLElement["b", {}, {"namepart1"}], "namepart2"} ]}]

... which gives the result {}.

How can I extract just the text "namepart1namepart2 in this second case?

Source Link
zongxian
  • 901
  • 4
  • 9

Filter Information form XML format file

I want filter information from a .xml file, the general xml rule is

XMLElement["div", {"class" -> "art_title linkable"}, {XMLElement["a", 
{"shape" -> "rect", "class" -> "ref nowrap", 
"href" -> "XXXX"}, {"name"}]}]

so I use the following code, it will word good,

Cases[data, 
 XMLElement[
    "div", {"class" -> "art_title linkable"}, {XMLElement[
      "a", {___}, {papername_}]}] :> {papername}, {0, Infinity}];

But I found there are special condition,

XMLElement["div", {"class" -> "art_title linkable"}, {XMLElement[
   "a", {"shape" -> "rect", "class" -> "ref nowrap", 
    "href" -> "XXXX"}, {XMLElement[
     "b", {}, {"namepart1"}], 
    "namepart2"}]}]

The name of the special form can't use the code, so I hope someone can help me, if there is a method can get the name for the spectial condtion.