alanchinese Posted December 29, 2008 Posted December 29, 2008 Hi, Is there a simple and efficient way to create an XML from a segmented string? For example, I would like to convert the following string (is there a better name for this kind of strings?): SEG_ROOT_START*1234~ SEG_LVL1*A*B~ SEG_LVL2*8~ SEG_LVL1*X*~ SEG_ROOT_END~ into: <SEG_ROOT> <SEG_LVL1> <SEG_LVL1_01>A</SEG_LVL1_01> <SEG_LVL1_02>B</SEG_LVL1_02> <SEG_LVL2> <SEG_LVL2_01>8</SEG_LVL2_01> </SEG_LVL2> </SEG_LVL1> <SEG_LVL1> <SEG_LVL1_01>X</SEG_LVL1_01> <SEG_LVL1_01 /> </SEG_LVL1> </SEG_ROOT> In this example, The root segment has two forms, one for begin, one for end. We need to parse this specially There are two levels, LVL1 (expecting two string childrens) and LVL2 (expecting one integer child) Level LVL2 can only be children of LVL1 When an expected value shows an empty string, the corresponding XML node shouuld be NULL. Currently, we are reading and parsing these strings manually. I am wondering if there are existing ways (regular expressions, maybe?) so that we can convert them into XMLs. We can do the following with the XMLs: Data validation once XSD is defined. Data transformation once XSLT is defined. Data transmission via web services. Thanks a lot for any information or suggestions, Alan. Quote
Nate Bross Posted December 29, 2008 Posted December 29, 2008 If you are processing them manually, as long as you are using the StringBuilder class you're probably not going to get much better performance than that. There may be an elegent way to use regular expressions, but I'll have to defer to someone else. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Diesel Posted December 29, 2008 Posted December 29, 2008 I've had a good amount of experience with xml, and no, I'd say in this case, there's no parsing shortcut. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.