File tree 4 files changed +16
-25
lines changed
4 files changed +16
-25
lines changed Original file line number Diff line number Diff line change 28
28
except : pass
29
29
30
30
import System
31
- import xml .etree .ElementTree as ET
32
31
from Grasshopper .Kernel .Data import GH_Path
33
32
from Grasshopper import DataTree
34
33
import re
34
+ import clr
35
+ clr .AddReference ("System.Linq" )
36
+ clr .AddReference ("System.XML.Linq" )
37
+ from System .Xml .Linq import XDocument
35
38
36
39
ghenv .Component .Message = "1.1.0"
37
40
38
-
39
-
40
- def get_clean_xml (text ):
41
-
42
- characters = '[^\s()_<>/,\.A-Za-z0-9=""]+'
43
- text = re .sub (characters , '' , text )
44
- return text
45
-
46
-
47
41
def main ():
48
42
49
43
if _XML and _keyword :
50
44
51
- roots = [ET . fromstring ( get_clean_xml ( el ) ) for el in _XML ]
45
+ xdocs = [XDocument . Parse ( el ) for el in _XML ]
52
46
results = DataTree [System .Object ]()
53
47
54
48
for i , key in enumerate (_keyword ):
55
49
path = GH_Path (0 , i )
56
- results .AddRange ( [root . find ( key ). text for root in roots if root . find (key ) != None ] ,path )
50
+ results .AddRange ( [element . Value for xdoc in xdocs for element in xdoc . Descendants (key ) ] ,path )
57
51
58
52
return results
59
53
else :
Original file line number Diff line number Diff line change @@ -75,17 +75,14 @@ public Library(string file,
75
75
76
76
private string GetCompatibleText ( string file )
77
77
{
78
- string characters = @"[^\s()_<>/,\.A-Za-z0-9=""]+" ;
79
- Encoding encoding = Encoding . UTF8 ;
78
+ string characters = @"[^\s()_<>/,\.A-Za-z0-9=""\P{IsBasicLatin}]+" ;
80
79
81
80
if ( ! System . IO . File . Exists ( file ) )
82
81
throw new Exception ( $ "{ file } not found.") ;
83
- string text = System . IO . File . ReadAllText ( file , encoding ) ;
82
+ string text = System . IO . File . ReadAllText ( file ) ;
83
+ string res = Regex . Replace ( text , characters , "" ) ;
84
84
85
- text = System . Net . WebUtility . HtmlDecode ( text ) ;
86
- Regex . Replace ( characters , "" , text ) ;
87
-
88
- return text . Replace ( "&" , "" ) ;
85
+ return res ;
89
86
}
90
87
91
88
private void SetLibrary ( string file , string type , string keyword )
Original file line number Diff line number Diff line change @@ -27,14 +27,14 @@ public Read(string path)
27
27
28
28
private string ReadEdxFile ( string path )
29
29
{
30
- string characters = @"[^\s()_<>/,\.A-Za-z0-9=""]+" ;
31
- Encoding isoLatin1 = Encoding . GetEncoding ( 28591 ) ; ;
32
- string text = System . IO . File . ReadAllText ( path , isoLatin1 ) ;
30
+ string characters = @"[^\s()_<>/,\.A-Za-z0-9=""\P{IsBasicLatin}\p{IsLatin-1Supplement}]+" ;
33
31
34
- Regex . Replace ( characters , "" , text ) ;
32
+ if ( ! System . IO . File . Exists ( path ) )
33
+ throw new Exception ( $ "{ path } not found.") ;
34
+ string text = System . IO . File . ReadAllText ( path ) ;
35
+ string res = Regex . Replace ( text , characters , "" ) ;
35
36
36
- return text . Replace ( "&" , "" )
37
- . Replace ( "<Remark for this Source Type>" , "" ) ;
37
+ return res . Replace ( "<Remark for this Source Type>" , "" ) ;
38
38
}
39
39
40
40
private static string GetValueFromXml ( XmlNodeList nodeList ,
You can’t perform that action at this time.
0 commit comments