473,238 Members | 3,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

parsing URL and read xml data

Hi

I have an url where I have xml data POSTED and I need to parse the URL to
read the data - Meanwhile here is my xml data
===================================
<?xml version="1.0" encoding="utf-16"?>
<?adf version="1.0"?>
<!DOCTYPE adf SYSTEM "http://whoscalling.com/dtd/adfdtd.dtd">
<adf>
<prospect status="new">
<id sequence="1" source="WhosCalling">93957229</id>
<requestdate>2004-03-04T16:05:38-08:00</requestdate>
<vehicle>
<year>N/A</year>
<make>N/A</make>
<model>N/A</model>
</vehicle>
<customer>
<contact>
<name part="first">WhosCalling</name>
<name part="last">Caller</name>
<phone type="voice">7149968905</phone>
</contact>
<id sequence="1" source="WhosCalling">7149968905</id>

<comments><![CDATA[<call><duration>PT55S</duration><status>Completed</status
<recordingUrl>http://www.whoscalling.com/vvcallred...21MW%40V%22KO%

2069S%5BO%5F%3BWP%20%20%0A</recordingUrl><tollFreeNumber>8882800498</tollFre
eNumber><redirect>7145774394</redirect></call>]]></comments>
</customer>
<vendor>
<id sequence="1" source="WhosCalling">7179</id>
<id sequence="2" source="WCAgentID">0</id>
<vendorname>CRM Test Account - Penny Saver USA</vendorname>
<contact primarycontact="1">
<name part="full"></name>
<email></email>
<phone></phone>
</contact>
</vendor>
<provider>
<id sequence="1" source="WhosCalling">160938</id>
<id sequence="2" source="PartnerData"></id>
<id sequence="3" source="ExternalIDName"></id>
<name part="full">Who's Calling, Inc.</name>
<service>8882800498</service>
<url>http://www.whoscalling.com</url>
<email>ad*******@whoscalling.com</email>
<phone>4255766000</phone>
<contact primarycontact="1">
<name part="full">Nationals</name>
<email>na*******@whoscalling.com</email>
<phone>8669688888</phone>
</contact>
</provider>
</prospect>
</adf>

===================================
and here is the way I am doing - unless I comment above DOCTYPE line in
above xml file it doesn't work
===================================
dim xmldoc, data
Set xmldoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocumen t.4.0")
xmldoc.async = false
xmldoc.resolveExternals = false
xmldoc.validateOnParse = false
xmldoc.load(Request)
xmldoc.save(Server.MapPath("transfers/saved1.xml"))
===================================
Thanks

Gary
Jul 19 '05 #1
8 4553
Hi Gary,

With deeper research on this issue, I found the problem is related to ASP
application's permission. I test the XML data and code in a windows
application:

Dim xmldoc, data
Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
xmldoc.async = False
xmldoc.resolveExternals = True
xmldoc.validateOnParse = True
Dim ss

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

Dim ff

Set ff = fso.OpenTextFile("c:\case\edit1.xml")

ss = ff.readall

ff.Close
MsgBox xmldoc.loadxml(ss)

xmldoc.save ("c:\case\saved1.xml")

Above code work great. But when I move them in an ASP application, it can't
load the XML data.

Then I put the dtd file in local disk:

<!DOCTYPE adf SYSTEM "c:\adfdtd.dtd">

And then, the asp application begin to work.

Therefore, the root cause of the problem should be that the ASP application
doesn't have enough permission to access DTD on internet, it can only
access on local disk. You may try this on your side.

Additionally, resolveExternals should be set to true on both of client and
server side:

objXMLDocument.resolveExternals = True

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #2
Well Luke, we don't have any control on the xml file as it is provided by
the service provider and they won't change as it is working for their other
clients. NOW the deal is to make it work without changing any - I think I
got over the doctype node by setting resolveexternals and validateonparse to
false however I encountering with "Switch from current encoding to specified
encoding not supported." while posting the xml file - please remember that
posting is just for testing our MAIN job is to receive the data since they
are posting it to our URL

We do have tech support - what is the number I call, thanks

"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:T1*************@cpmsftngxa06.phx.gbl...
Hi Gary,

With deeper research on this issue, I found the problem is related to ASP
application's permission. I test the XML data and code in a windows
application:

Dim xmldoc, data
Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
xmldoc.async = False
xmldoc.resolveExternals = True
xmldoc.validateOnParse = True
Dim ss

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

Dim ff

Set ff = fso.OpenTextFile("c:\case\edit1.xml")

ss = ff.readall

ff.Close
MsgBox xmldoc.loadxml(ss)

xmldoc.save ("c:\case\saved1.xml")

Above code work great. But when I move them in an ASP application, it can't load the XML data.

Then I put the dtd file in local disk:

<!DOCTYPE adf SYSTEM "c:\adfdtd.dtd">

And then, the asp application begin to work.

Therefore, the root cause of the problem should be that the ASP application doesn't have enough permission to access DTD on internet, it can only
access on local disk. You may try this on your side.

Additionally, resolveExternals should be set to true on both of client and
server side:

objXMLDocument.resolveExternals = True

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #3
Hi Luke

Basically the DATA provider who is posting data to our URL has sent this
sample code showing HOW TO RECIEVE THEIR DATA - could you please guide me to
convert this code to ASP perhaps this is c# which I am not aware. Here is
the sample code:
======================================
private enum ReturnCode { Success, Error, NoData, FileIOError };

private void Page_Load(object sender, System.EventArgs e)
{
ReturnCode returnCode = ReturnCode.Success;

try
{
returnCode = Upload();
}
catch
{
returnCode = ReturnCode.Error;
}
finally
{
Response.Output.Write( "<result><returnCode>{0}</returnCode></result>",
returnCode );
}
}

private ReturnCode Upload()
{
ReturnCode returnCode = ReturnCode.Success;

//
// Make sure we have something to work with
//
int bLen = Context.Request.ContentLength;
if( bLen > 0 )
{
//
// The body contains XML formatted as ADF...
// so convert the bytes to string.
//
byte[] bytes = Context.Request.BinaryRead( bLen );
string msg = Encoding.ASCII.GetString( bytes, 0, bLen );

//
// At this point we have some data and we expect
// it to be an ADF report, which is valid XML.
//
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager( nt );
XmlParserContext pc = new XmlParserContext( null, nsmgr, null,
XmlSpace.None );
XmlValidatingReader xmlReader = new XmlValidatingReader( msg,
XmlNodeType.Document, pc );

//
// The Microsoft XML parser cannot resolve the
// colorcombination element... so for now, just
// disable the validation.
//
xmlReader.ValidationType = ValidationType.None;

//
// Load the document
//
XPathDocument xDoc = new XPathDocument( xmlReader );
XPathNavigator nav = xDoc.CreateNavigator();

//
// Find the call id so that we can use it as a filename.
//
string cdrID = null;
XPathNodeIterator iter = nav.Select( "/adf/prospect" );
while( iter.MoveNext() && cdrID == null )
{
XPathNodeIterator prospectIter = iter.Current.SelectChildren(
XPathNodeType.Element );
while( prospectIter.MoveNext() )
{
if( string.Compare( prospectIter.Current.Name, "id", true ) == 0 )
{
cdrID = prospectIter.Current.Value;
break;
}
}
}

try
{
if( cdrID != null )
{
string dir = ConfigurationSettings.AppSettings[ "DataFileDir" ];
if( dir == null || dir.Length == 0 )
{
// default to the current directory
dir = ".";
}

string fileName = string.Format( @"{0}\{1}.xml", dir, cdrID );

using( StreamWriter writer =
new StreamWriter( new FileStream( fileName, FileMode.Create ),
System.Text.Encoding.ASCII ) )
{
writer.WriteLine( msg );
}
}
}
catch
{
returnCode = ReturnCode.FileIOError;
}
}
else
{
returnCode = ReturnCode.NoData;
}

return returnCode;
}

================================================
Thanks much!

Garyrek
"Garyrek" <Ga*****@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
Well Luke, we don't have any control on the xml file as it is provided by
the service provider and they won't change as it is working for their other clients. NOW the deal is to make it work without changing any - I think I
got over the doctype node by setting resolveexternals and validateonparse to false however I encountering with "Switch from current encoding to specified encoding not supported." while posting the xml file - please remember that
posting is just for testing our MAIN job is to receive the data since they
are posting it to our URL

We do have tech support - what is the number I call, thanks

"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:T1*************@cpmsftngxa06.phx.gbl...
Hi Gary,

With deeper research on this issue, I found the problem is related to AS P application's permission. I test the XML data and code in a windows
application:

Dim xmldoc, data
Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
xmldoc.async = False
xmldoc.resolveExternals = True
xmldoc.validateOnParse = True
Dim ss

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

Dim ff

Set ff = fso.OpenTextFile("c:\case\edit1.xml")

ss = ff.readall

ff.Close
MsgBox xmldoc.loadxml(ss)

xmldoc.save ("c:\case\saved1.xml")

Above code work great. But when I move them in an ASP application, it

can't
load the XML data.

Then I put the dtd file in local disk:

<!DOCTYPE adf SYSTEM "c:\adfdtd.dtd">

And then, the asp application begin to work.

Therefore, the root cause of the problem should be that the ASP

application
doesn't have enough permission to access DTD on internet, it can only
access on local disk. You may try this on your side.

Additionally, resolveExternals should be set to true on both of client and server side:

objXMLDocument.resolveExternals = True

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Jul 19 '05 #4
Hi Gary,

Converting these code may be impossible, it use some particular datatype
which is not supported in ASP, for example, byte[]. If we only need to save
the request in a XML file, we may use "ADODB.Stream":
if Request.TotalBytes >0 then

dim post_ret

post_ret=Request.BinaryRead(Request.TotalBytes)
dim ado_stream

set ado_stream=server.CreateObject("adodb.stream")

ado_stream.Type=2

ado_stream.Open

ado_stream.Write post_ret
ado_stream.SaveToFile "c:\data.xml",2
end if

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #5
Hi Luke

That works! thanks finally. As of now, our site might get 10-20 hits per day
might grow in future, What would be the best way to store the data.

Should I pull the xml data from the file and store it in the database or
what other way? I guess my question is How should I organize the content
according to the car dealer name, since all that xml file consists is Dealer
and customer details, Using this data I need to send an report to dealer.

Thanks a bunch! any way.
"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:nE**************@cpmsftngxa06.phx.gbl...
Hi Gary,

Converting these code may be impossible, it use some particular datatype
which is not supported in ASP, for example, byte[]. If we only need to save the request in a XML file, we may use "ADODB.Stream":
if Request.TotalBytes >0 then

dim post_ret

post_ret=Request.BinaryRead(Request.TotalBytes)
dim ado_stream

set ado_stream=server.CreateObject("adodb.stream")

ado_stream.Type=2

ado_stream.Open

ado_stream.Write post_ret
ado_stream.SaveToFile "c:\data.xml",2
end if

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #6
By the way ado_stream.type = 1 works, that means I have binary data
coming....
"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:nE**************@cpmsftngxa06.phx.gbl...
Hi Gary,

Converting these code may be impossible, it use some particular datatype
which is not supported in ASP, for example, byte[]. If we only need to save the request in a XML file, we may use "ADODB.Stream":
if Request.TotalBytes >0 then

dim post_ret

post_ret=Request.BinaryRead(Request.TotalBytes)
dim ado_stream

set ado_stream=server.CreateObject("adodb.stream")

ado_stream.Type=2

ado_stream.Open

ado_stream.Write post_ret
ado_stream.SaveToFile "c:\data.xml",2
end if

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #7
Hi Gary,

From my experience, you can considering converting the XML document to
datas in database and then generate report from the database. The data will
be well organized and easy to manage.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #8
Hi Luke,

Ok, considering your approach - How do I do that? I believe you basically
load using xmldom retrive the values you want and insert into the database -
Now, should I save as a separate document on each hit the URL gets using
TIMESTAMP (using NOW function in vbscript - now, will that record to
milliseconds?) if not, will it overwrite everyhit considering the scenario
where two users hit the site at same SECOND/MINUTE or will it record only
one user's data, Please advise.

Secondly, Instead of saving it as an XML file can I get store it in the
database directly, I have sqlserver 7.0 though, i don't think it supports
FOR XML command.

Thirdly, getting stuck on first step where loading the XML file using
xmldom - remember the error "Switch from current encoding to specified
encoding not supported." I know I can use fileobject and replace the
encoding attribute from utf-16 with utf-8 however this can be done perhaps
by simply setting the xmldom attribute? I tried validateonparse = false and
resolveExternals = false didn't work.

Thanks much for All.

Gary

"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:7b*************@cpmsftngxa06.phx.gbl...
Hi Gary,

From my experience, you can considering converting the XML document to
datas in database and then generate report from the database. The data will be well organized and easy to manage.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Kylotan | last post by:
I have a text file where the fields are delimited in various different ways. For example, strings are terminated with a tilde, numbers are terminated with whitespace, and some identifiers are...
3
by: Willem Ligtenberg | last post by:
I decided to use SAX to parse my xml file. But the parser crashes on: File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception...
5
by: Rafal 'Raf256' Maj | last post by:
Hi, I need to parse a file. This means reading from it as from std::istream. But - sometimes I also need to put-back some text I read before. What type of string can I use for that? Something...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
1
by: Christoph Bisping | last post by:
Hello! Maybe someone is able to give me a little hint on this: I've written a vb.net app which is mainly an interpreter for specialized CAD/CAM files. These files mainly contain simple movement...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
3
by: Cuong.Tong | last post by:
Greeting, I am writing my own web server and having some problme parsing the the mulitpart/form-data stream that is sent from the browsers. I have a form looks something like this <form...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
2
by: Gary42103 | last post by:
Hi I need Perl Script to do Data Parsing using existing data files. I have my existing data files in the following directory: Directory Name: workfs/ams Data File Names: 20070504.dat,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.