Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear expert

i want to remove a line of xml.

my xml like this :

XML
POST / HTTP/1.1
Host: 192.168.0.21:2010
Content-Length: 725
Connection: Keep-Alive

<?xml version="1.0"?>
<Metrics SiteId="Company 1" Sitename="Lokasi 1" DeviceId="Device1" Devicename="Device_1">
<Properties>
<MacAddress>00:b0:9d:c8:ab:9b</MacAddress>
<IpAddress>192.168.0.123</IpAddress>
<HttpPort>80</HttpPort>
<HttpsPort>443</HttpsPort>
<HostName>Cam-13151131</HostName>
<HwPlatform>1100</HwPlatform>
<Timezone>7</Timezone>
<DST>0</DST>
<DeviceType>0</DeviceType>
<SerialNumber>13151131</SerialNumber>
</Properties>
<ReportData Interval="1">
<Report Date="2015-03-24">
<Object Id="0" DeviceId="Device1" DeviceName="Device_1" ObjectType="0" Name="New Zone0">
<Count StartTime="09:26:27" EndTime="09:27:00" Enters="1" Exits="2" Status="0"/>
</Object>
</Report>
</ReportData>
</Metrics>


i want to remove line

VB
POST / HTTP/1.1
Host: 192.168.0.21:2010
Content-Length: 725
Connection: Keep-Alive

(white space)

so my first line start from


please somebody help me
Posted
Comments
Sergey Alexandrovich Kryukov 24-Mar-15 0:08am    
No, this is not XML... :-)
How did you manage to receive HTTP package with all headers in such a row form in first place? You don't really need to remove anything.
—SA
nanda destyandana 24-Mar-15 0:10am    
so what kind of this ?

can you help me ?

Sergey Alexandrovich Kryukov 24-Mar-15 0:17am    
This is HTTP request. By where is a header like "Content-Type: text/xml; charset=UTF-8"?
Anyway, how did you get it?
—SA
nanda destyandana 24-Mar-15 0:24am    
dataFromClient = System.Text.Encoding.UTF8.GetString(byteFrom, 0, i)

Dim doc As XmlDocument = New XmlDocument()
doc.Load(dataFromClient)

my error is :
the root level is invalid. Line 1, position 1. or
illegal character

so i guest that error is from that line.


Sergey Alexandrovich Kryukov 24-Mar-15 0:26am    
Of course. Forget it. How. Did. You. Get. dataFromClient?
—SA

1 solution

This is not XML. XML is starting from the prolog <?xml version="1.0"?>, and those first lines are the HTTP request lines. Please see my comment to the question.

Removing some lines from the string is the trivial issue (does anyone really need to help with that? :-)), but this is not what you probably want to do.

Please see: https://msdn.microsoft.com/en-us/library/system.web.httprequest%28v=vs.110%29.aspx.

The first example shows how an ASP.NET page can handle HTTP request sent to the server side from a client requesting some page; by using the Request property of the Page class. You can get a network stream using one of the Get*Stream methods and read all the request data. In this case, you get it without HTTP request headers, which can be accessed via those System.Web.HttpRequest properties. In other words, the parsing of raw HTTP text block is already done for you.

Sorry, I have no idea how did you obtain the text you've shown. Probably you did something else. No matter. Thank you for explaining how you got the raw HTTP request in your reply to my comment, but I have no idea why. Most likely, you need to so what I described above. If you wanted to do something else, please explain.

See also: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol.
You really need to get an idea on how Web works.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900