c# - Parsing XML with spaces in element names -


So I have to parse a simple XML file (only one level, no attribute, only element and value) but The problem is that the blank space (or may be) in the XML I know is bad (potentially horrible) practice, but I'm not the one who is building XML, it is coming from an external library. >

Example:

  & lt; Live key & gt; Exam & lt; / Live key & gt; & Lt; No G & gt; Trial & lt; / No & gt; & Lt; Test & gt; Hello & lt; / Test & gt;    

Now my tactic is XML (I have a string as a) at the same time reading a letter and just the name of each element and Save the value as I get it, but it seems a little too complicated.

Is there any easy way to do this? XMLReader throws an error because it thinks that XML is well formed, thus it thinks that "living" is the name of the element and "key" is a feature, so it "=" And a "& gt;"

Unfortunately, the text returned by your library is well There is not a built-in XML, so you can not use it to parse the XML parser. Spaces in the tag are only part of the problem; For example, the absence of "root" tags, there are other problems.

Fortunately, a single-level language is trivial enough to match regularly with the expression. Regex-based "parser" will be an awesome option for the real XML, but this language is not real, so you can use regex as a workaround at least:

  Regex rx = new Regex ("& lt; ([^> \ n] *)> (*.)   

The idea behind this approach is to find the wire with the "opening tag" which matches slash with "closed tag".

Here's one, it has the following output for your input:

  live key = 'test'. G = 'test' test = 'hello'    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -