tags:

views:

99

answers:

4

My Question

I have an xml file with invalid syntax first of all, second i cant do anything to change it, due to the company thats feeding the xml.

I have element nodes that i need to gut out the space, how can i do that VIA C# .NET

I also have the option to get the data via a CSV format instead, thinking it might be easier to replace the values as a CSV rather then some XML String, but i just don't know how or the best way.

Example

Provided: <Avg Pos> value </Avg Pos>

Required: <AvgPos> value </AvgPos>

A: 

You're probably going to be better off getting the CSV, because the XML they're feeding you is malformed. In XML, because of the way tag naming works, there's a BIG difference between "TagName" and "Tag Name". It sounds like they're delivering completely invalid XML (NO XML client will be able to read that properly, according to the example you give); you should try to get them to correct the error, but if they won't / can't, try dealing with the CSV.

McWafflestix
the CSV has the same format for the element node, i need to convert the Invalid XML to Valid XML in order to import the data into a SQL Database. Any other solutions? I already put in a request to the company to change their XML, but they wont for the time being.
sia
You've got some funny company there if they call that XML I don't wanna see what they call HTML Transitional 4.0 ...
ApoY2k
i know, its terrible
sia
Where is the valid XML specified?
McWafflestix
A: 

You better tell them what XML really means, 'cause that thing you posted there is far away from anything that has the right of being called XML...

In that case, go for the CSV, read in every row and strip out the spaces (e.g. _Row.Replace(" ", "");), save it in a new .XML and you should be good to go.

ApoY2k
A: 

If you never have any attributes inside the tags you could:

  1. figure out all the element names
  2. determine their malformed open and close tag equivalent.
  3. replace all malformed tags with their wellformed equivalent in the entire document

But if my employer gave me that stuff and said it was XML, I'd know it was time to switch jobs.

Kris
A: 

This was really what i was looking for...

iReportPath

TextReader origXML = new StreamReader(iReportPath + iFileName);

string validXMLString = HttpContext.Current.Server.HtmlEncode(origXML.ReadToEnd().ToString());

validXMLString = validXMLString.Replace("Avg Pos", "AvgPos");

validXMLString = validXMLString.Replace("Avg CPC", "AvgCPC");

validXMLString = validXMLString.Replace("Gr. Rev", "Gr.Rev");

validXMLString = HttpContext.Current.Server.HtmlDecode(validXMLString);

origXML.Close();

validXMLString value is what i needed!

sia