Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4406 > unrolled thread

Re: Getting the Date and Time From a Time Server

Started by"Hans Michel" <hmichel@cox.net>
First post2011-08-15 00:19 +0000
Last post2011-08-15 00:19 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Getting the Date and Time From a Time Server "Hans Michel" <hmichel@cox.net> - 2011-08-15 00:19 +0000

#4406 — Re: Getting the Date and Time From a Time Server

From"Hans Michel" <hmichel@cox.net>
Date2011-08-15 00:19 +0000
SubjectRe: Getting the Date and Time From a Time Server
Message-ID<j29onc$7a9$1@smc.vnet.net>
First of all need more information than what you get.

 

In[3]:= XML`Parser`XMLGetString["<?xml version='1.0' \

encoding='UTF-8'?><!DOCTYPE NISTTime [<!ENTITY datetime SYSTEM

          'http://time.nist.gov:13/'><!ELEMENT NISTTime \

(#PCDATA)>]><NISTTime>&datetime;</NISTTime>"]

 

Out[3]= XMLObject[

  "Document"][{XMLObject["Declaration"]["Version" -> "1.0", 

   "Encoding" -> "UTF-8"], 

  XMLObject["Doctype"]["NISTTime", 

   "InternalSubset" -> 

    "<!ENTITY datetime SYSTEM 'http://time.nist.gov:13/'><!ELEMENT \

NISTTime (#PCDATA)*>"]}, 

 XMLElement[

  "NISTTime", {}, {"55787 11-08-14 18:45:50 50 0 0 823.4 UTC(NIST) \

*"}], {}, "Valid" -> True]

 

http://reference.wolfram.com/mathematica/XML/tutorial/ImportingXML.html

 

This works for me also. Have you tried just using the URL in your browser on
your network. Port 13 may be blocked. 

If not blocked then try the following.

 

XML`Parser`XMLGetString["<?xml version='1.0' \

encoding='UTF-8'?><!DOCTYPE NISTTime [<!ENTITY datetime SYSTEM

          'http://time.nist.gov:13/'><!ELEMENT NISTTime \

(#PCDATA)>]><NISTTime>&datetime;</NISTTime>", 

 "AllowRemoteDTDAccess" -> True, "AllowUnrecognizedEntities" -> True, 

 "ValidateAgainstDTD" -> True]

 

In original reply I also stated that it may not work in your system due to
firewall issue or Mathematica front end setting and XML parser settings

 

("AllowUnrecognizedEntities" in XML attributes in Mathematica is defaulted
to True. If entities can not be fetched on your system you may need to
adjust this attribute in Mathematica. There may also be firewall issues.)

 

You may want to try the route of GetURL and excape out to Java.

http://library.wolfram.com/examples/GetURL/

 

Hans

 

From: Gregory Lypny [mailto:gregory.lypny@videotron.ca] 
Sent: Sunday, August 14, 2011 1:01 PM
To: Hans Michel
Cc: mathgroup@smc.vnet.net
Subject: Re: Getting the Date and Time From a Time Server

 

Hi Hans,

 

Thank you for the script.  Unfortunately, I get the following Mathematica
error message when I run it.

 

 

XML`Parser`XMLGetString::prserr: NetAccessorException: Could not open file:
http://time.nist.gov:13/ at Line: 2 Character: 88.

 

 

Regards,

 

Gregory

 

 

On Sat, Aug 13, 2011, at 2:49 PM, Hans Michel wrote:





Using Mathematica Version 7

$Version

"7.0 for Microsoft Windows (32-bit) (February 18, 2009)"

Import["http://time.nist.gov:13/"]
With port numbers fails.

Try the following trick: 

In[1]:= getNISTTime[] := 
 Module[{NISTTimeXML, result}, 
  NISTTimeXML = 
   ImportString[
    "<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE NISTTime \
[<!ENTITY datetime SYSTEM
         'http://time.nist.gov:13/'><!ELEMENT NISTTime \
(#PCDATA)>]><NISTTime>&datetime;</NISTTime>", "XML"];
  result = 
   First[Cases[NISTTimeXML, XMLElement["NISTTime", {}, ___], 
       Infinity]][[3]][[1]];
  result];


In[2]:= getNISTTime[]

Out[2]= "55786 11-08-13 18:24:53 50 0 0 441.7 UTC(NIST) *"

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web