【发布时间】:2013-12-19 04:31:48
【问题描述】:
请帮忙!你的几分钟可以节省我几个小时!
我正在使用 PIG 获取一些信息。
<Content
<Name ><\Name>
<Data ><\Data>
<Data ><\Data>
><\Content>
所以我用了:
abcd_ = LOAD 'parentFolder/*' USING org.apache.pig.piggybank.storage.XMLLoader('Content') AS (content: chararray);
我只需要一些具体的信息,我不知道有没有可能:
abcd_ = LOAD 'parentFolder/*' USING org.apache.pig.piggybank.storage.XMLLoader('Content','Data') AS (content: chararray,data: chararray);
但我希望避免这种情况。我已经在 XMLLoader 之后使用正则表达式成功提取了我的其他信息,但以下内容除外(只是可能的字符组合示例)
<Data Name="Buffer">{"$type"System.Collections.Generic'[!#%,:()!@-;[.}<\Data>
我的正则表达式:
1. \\<Data Name=\\"Buffer\\"\\>\\{(.*)\\}\\<\Data\\> -- Unexpected character D at <\Data>
2. \\<Data Name=\\"Buffer\\"\\>\\{(.*)\\}\\<\\Data\\> -- I got nothing
3. \<Data Name=\"Buffer\"\>\{(.*)\}\<\\Data\> -- Unexpected character < at \<Data Name..
4. \\<Data Name=\\"Buffer\\"\\>\\{(.*)\\}\\<\\\Data\\> -- Unexpected character D at <\\\Data>
我打算得到:
"$type"System.Collections.Generic'[!#%,:()!@-;[.
编辑:
刚刚意识到一个巨大的错误,\应该是/
-
找到答案
<Data Name=\\"Buffer\\">\\{(.*)\\}</Data\\>
【问题讨论】:
-
如果你正确解析你的xml而不是使用正则表达式,你会更好。
-
我明白了,我会尝试看看我要避免的事情是否可行。
-
呃不能,我对大数据和 xml 很陌生,实际上正确解析我的 xml 是什么意思?请您再解释一下好吗?
标签: java xml regex apache-pig