Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hello,
I am looking to learn how to get information from a .XML website and then parsing through the data and whenever it reaches a <name> or <product_description> to take that information and write it into the infotable. I have absolutely no clue how to do this so I need a lot of help.
Thank you,
Mike
Hi Michael, what is the use case for this btw? Is this temporary information going out to the mashup or information that you wish to store for a period or permanent?
As to how to do this, please look in the Training section and look for a Video on Services/Consuming an external web page.
That should get you up and going.
It won't need to be permanent as the script will have to redownload the XML file every five minutes to check for updates so it will be purely for display in a mashup. I will watch the video and let you know if I have any questions.
Thanks Pai!
Pai,
Getting an error when running the first part of the video for my xml website (the loadxml snippet)
Wrapped java.lang.IllegalArgumentException: Illegal character in path at
index 0: \mespabeloitsharedProductionMonitorProdMonProduct2.xml Cause:
Illegal character in path at index 0:
\mespabeloitsharedProductionMonitorProdMonProduct2.xml
the website uses \ instead of / and I am assuming that is messing up the code.
Let me know if I am wrong.
Thank you,
Mike Francek
it seems the website is not so much a website but an XML document on our internal network. Would there be a different way I go about getting this XML information into Thingworx?
Thingworx can load it, if it is a proper URL or if it is in the File Repository.
file://server01\fshare\dir1\dir2\dir3\NameofFile
I am not getting the following error.
Wrapped org.apache.http.client.ClientProtocolException Cause: null
I switched the URL to read as the following
file://mespabeloit/shared/ProductionMonitor/ProdMonProduct2.xml
A standard way I approach this is to first set the return type of the service as String and use GetText vs. GetXML and test that first.
still getting the error. My output is set to String. Below is the code I used.
var params = {
headers: undefined /* JSON /,<br> useProxy: undefined / BOOLEAN /,<br> proxyHost: undefined / STRING /,<br> useNTLM: undefined / BOOLEAN /,<br> ignoreSSLErrors: undefined / BOOLEAN /,<br> proxyPort: undefined / INTEGER /,<br> withCookies: undefined / BOOLEAN /,<br> password: undefined / STRING /,<br> url: 'file://mespabeloit\shared\ProductionMonitor\ProdMonProduct2.xml' / STRING /,<br> workstation: undefined / STRING /,<br> username: undefined / STRING /,<br> proxyScheme: undefined / STRING /,<br> domain: undefined / STRING /,<br> timeout: undefined / NUMBER */
};
// result: STRING
var result = Resources["ContentLoaderFunctions"].GetText(params);
What messages do you see in the application log?
[context: com.thingworx.webservices.context.HttpExecutionContext@5051fe6c][message: Execution error in service script [BeloitPCPackaging Test_Get_ICS_Information] : Wrapped org.apache.http.client.ClientProtocolException Cause: null]
Temporarily let's eliminate the file location.
Pai,
Getting the following error. Wrapped java.lang.IllegalStateException: Target host is null Cause: Target host is null
code is below
var params = {
headers: undefined /* JSON /,<br> useProxy: undefined / BOOLEAN /,<br> proxyHost: undefined / STRING /,<br> useNTLM: undefined / BOOLEAN /,<br> ignoreSSLErrors: undefined / BOOLEAN /,<br> proxyPort: undefined / INTEGER /,<br> withCookies: undefined / BOOLEAN /,<br> password: undefined / STRING /,<br> url: '7.135.69.57/Thingworx/ProdMonProduct2.xml' / STRING /,<br> workstation: undefined / STRING /,<br> username: undefined / STRING /,<br> proxyScheme: undefined / STRING /,<br> domain: undefined / STRING /,<br> timeout: undefined / NUMBER */
};
// result: STRING
var result = Resources["ContentLoaderFunctions"].GetText(params);
Try that with http:// or https:// in front of it.
it pulled the file when I used http:// but not when i used https://
Ok great. At least for now you can go ahead and work on the parsing and consumption.
Pai,
Do you know how I could find out the IP address of the machine/server?
Thank you for all the help!
not really my area of expertise, but you can try pinging it from your command prompt.
Pai,
Was finally able to get the web url issue figured out, however now I am receiving the following text instead of the file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>You are not authorized to view this
page</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html;
charset=Windows-1252">
<STYLE type="text/css">
BODY
H1
H2
A:link
A:visited
</STYLE>
</HEAD><BODY><TABLE width=500 border=0
cellspacing=10><TR><TD>
<h1>You are not authorized to view this page</h1>
You do not have permission to view this directory or page using the
credentials that you supplied because your Web browser is sending a
WWW-Authenticate header field that the Web server is not configured to
accept.
<hr>
<p>Please try the following:</p>
<ul>
<li>Contact the Web site administrator if you believe you should
be able to view this directory or page.</li>
<li>Click the <a
href="javascript:location.reload()">Refresh</a> button to try
again with different credentials.</li>
</ul>
<h2>HTTP Error 401.2 - Unauthorized: Access is denied due to
server configuration.<br>Internet Information Services
(IIS)</h2>
<hr>
<p>Technical Information (for support personnel)</p>
<ul>
<li>Go to <a
href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft Product
Support Services</a> and perform a title search for the words
<b>HTTP</b> and <b>401</b>.</li>
<li>Open <b>IIS Help</b>, which is accessible in IIS
Manager (inetmgr),
and search for topics titled <b>About Security</b>,
<b>Authentication</b>, and <b>About Custom Error
Messages</b>.</li>
</ul>
</TD></TR></TABLE></BODY></HTML>
I can access the web url on the server in a web browser, but for some reason it seems I can't access it through Thingworx. Any suggestions?
Thank you,
Mike
Is there some type of way I can map it as a network drive on the server and access it that way?
Looks like the account that Thingworx is running under does not have permission to that drive or file. So mapping the drive wont make much of a difference I believe. Best to fix the permissions on the target box so Thingworx can get full access to them.