Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Client from Agent #9

Closed
tomsnell opened this issue Oct 7, 2014 · 14 comments
Closed

XML Client from Agent #9

tomsnell opened this issue Oct 7, 2014 · 14 comments
Assignees

Comments

@tomsnell
Copy link

tomsnell commented Oct 7, 2014

I am attempting to make a client in Visual Studio 2013 in vb.net. When I read it with the following code:

    Dim sAPIUrl As String = "http://localhost:5000/current?path=//Controller|//Power"
    Dim oDocument As XDocument = XDocument.Load(sAPIUrl)
    Dim sEstop = From Ev In oDocument...<Events> _
                 Select New MTEvents With {.EmergencyStop = Ev.<EmergencyStop>.Value, .Message = Ev.<Message>.Value}
    For Each ev In sEstop
        Console.WriteLine("Emergency Stop Status is {0}.", ev.EmergencyStop)
        Console.WriteLine("Message is ""{0}""", ev.Message)
    Next

It would not function, so I copied the XML code from the browser from my agent and attempted to manipulate it until I could get results. When I removed the reference to the XML schema, it would then give me the information from the xml file. I attempted to update the devices.xml file without the reference to the xml schema, it was still putting it in. I found something in the source code of the cppagent that was causing this, so I am thinking that the xml schema is correct. As shown in the picture, Visual Studio doesn't like the xsi. Anyone have any ideas on what I am missing?

So the xml that I used is (after removing the xsi:schemalocation...):

xmldata

@wsobel
Copy link
Member

wsobel commented Oct 7, 2014

The most likely reason is because the xsd file is not currently on the MTConnect website. The best way to configure the MTConnect agent is to have it serve the xsd files directly.

Files {
    schemas {
        Path = ./schemas
        Location = /schemas/
    }
}

Where the path points to the directory where you have the XSD files. This will automatically serve up and associate the XSD files with the correct document. The Location is the HTTP prefix for the XSD that gets mapped to the local direction referenced by Path. You need to copy the XSD files that come with the agent into that directory (already in zip file in schemas).

By default it shouldn't validate the schema, but it may still be trying to reference. I don't do VB, but in C# I used XElement.parse instead of XDocument.

Hope this helps.

@tomsnell
Copy link
Author

tomsnell commented Oct 7, 2014

If I add the information below to the agent.cfg:

Files {
schemas {
Path = ./schemas
Location = /schemas/
}
styles {
Path = ./styles
Location = /styles/
}
}

And put the folders (schemas and styles) from the source download in the same directory as the exe, this should cause it to use the stylesheet and the xsd files? I did this, but I did not put anything into the of the devices.xml. I’ve seen several examples of it, but I am new enough that it is hard to tell if I got it right. I am getting the message:

“This XML file does not appear to have any style information associated with it. The document tree is shown below.”

After doing that, so I am thinking I need to put something different. Do you have an example of what should go there if I am running the agent as localhost:5000/?

@wsobel
Copy link
Member

wsobel commented Oct 7, 2014

The files need to be in the subdirectory indicated by path, not the same directory. The Path is there to tell the agent where to find the files. ./schemas is the schemas subdirectory of the current directory.

The message that there is no style info is not a problem, the browser will use the default formatting and it will not matter for an application since it will skip the processing instructions and xslt step.

@tomsnell
Copy link
Author

Does the xsd file then need to be updated? I looked at the XSD file that was in the source code and found this:

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:vc='http://www.w3.org/2007/XMLSchema-versioning' xmlns='urn:mtconnect.org:MTConnectDevices:1.3' xmlns:mt='urn:mtconnect.org:MTConnectDevices:1.3' targetNamespace='urn:mtconnect.org:MTConnectDevices:1.3' elementFormDefault='qualified' attributeFormDefault='unqualified' vc:minVersion='1.1'>

This is still referencing mtconnect.org. Do all of these need to be changed from "mtconnect.org" to "localhost:5000" or to "localhost:5000/schemas"? Also, when referencing the schema in the xml file, do I replace every reference to mtconnect.org to localhost:5000/schemas or to localhost:5000?

@wsobel
Copy link
Member

wsobel commented Oct 13, 2014

There are only styles for the streams, not for the devices. You can add one of you want. The message has nothing to do with schema files.

Sent from my iPhone

On Oct 7, 2014, at 11:33, tomsnell notifications@github.com wrote:

If I add the information below to the agent.cfg:

Files {
schemas {
Path = ./schemas
Location = /schemas/
}
styles {
Path = ./styles
Location = /styles/
}
}

And put the folders (schemas and styles) from the source download in the same directory as the exe, this should cause it to use the stylesheet and the xsd files? I did this, but I did not put anything into the of the devices.xml. I’ve seen several examples of it, but I am new enough that it is hard to tell if I got it right. I am getting the message:

“This XML file does not appear to have any style information associated with it. The document tree is shown below.”

After doing that, so I am thinking I need to put something different. Do you have an example of what should go there if I am running the agent as localhost:5000/?

From: William Sobel [mailto:notifications@github.com]
Sent: Tuesday, October 07, 2014 1:27 PM
To: mtconnect/cppagent
Cc: Tom Snell
Subject: Re: [cppagent] XML Client from Agent (#9)

The most likely reason is because the xsd file is not currently on the MTConnect website. The best way to configure the MTConnect agent is to have it serve the xsd files directly.

Files {

schemas {

Path = ./schemas

Location = /schemas/

}

}

Where the path points to the directory where you have the XSD files. This will automatically serve up and associate the XSD files with the correct document. The Location is the HTTP prefix for the XSD that gets mapped to the local direction referenced by Path

By default it shouldn't validate the schema, but it may still be trying to reference. I don't do VB, but in C# I used XElement.parse instead of XDocument.

Hope this helps.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-58223598.

Reply to this email directly or view it on GitHub.

@tomsnell
Copy link
Author

My original problem is that I am trying to parse data from a machine. I used a text file version of what was coming from the machine (see my xml file on the original post). When I removed everything after the xsi:schemalocation=... it functioned. Then you said to put the XSD file on the local directory. I did that, but it still does the same thing. The agent source code adds its own XSD reference, so if I remove it completely from my devices.xml file, it still won't give me any data from my client because the agent code is referencing mtconnect.org. So I am trying to understand how to reference this file correctly in the devices.xml file and hopefully solve my original problem. All the examples that I could find reference the mtconnect.org web site and those files are no longer there, as you said.

@wsobel
Copy link
Member

wsobel commented Oct 13, 2014

I don't see the schema location at all.

On Monday, October 13, 2014, tomsnell notifications@github.com wrote:

Does the xsd file then need to be updated? I looked at the XSD file that
was in the source code and found this:

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:vc='
http://www.w3.org/2007/XMLSchema-versioning' xmlns='urn:mtconnect.org:MTConnectDevices:1.3'
xmlns:mt='urn:mtconnect.org:MTConnectDevices:1.3'
targetNamespace='urn:mtconnect.org:MTConnectDevices:1.3'
elementFormDefault='qualified' attributeFormDefault='unqualified'
vc:minVersion='1.1'>

This is still referencing mtconnect.org. Do all of these need to be
changed from "mtconnect.org" to "localhost:5000" or to
"localhost:5000/schemas"? Also, when referencing the schema in the xml
file, do I replace every reference to mtconnect.org to
localhost:5000/schemas or to localhost:5000?


Reply to this email directly or view it on GitHub
#9 (comment).

  • Will

Sent from my iPhone

@wsobel
Copy link
Member

wsobel commented Oct 13, 2014

The header in your message did not have a reference to the schema location
at all. The urn references mtconnect.org, but this does not reference the
site.

I would suggest looking into how the references work. I'm not sure what is
going wrong since your warning from the browser has nothing to do with the
schema.

If I'm going to help you need to dump the errors from the application, not
the browser.

On Monday, October 13, 2014, tomsnell notifications@github.com wrote:

My original problem is that I am trying to parse data from a machine. I
used a text file version of what was coming from the machine (see my xml
file on the original post). When I removed everything after the
xsi:schemalocation=... it functioned. Then you said to put the XSD file on
the local directory. I did that, but it still does the same thing. The
agent source code adds its own XSD reference, so if I remove it completely
from my devices.xml file, it still won't give me any data from my client
because the agent code is referencing mtconnect.org. So I am trying to
understand how to reference this file correctly in the devices.xml file and
hopefully solve my original problem. All the examples that I could find
reference the mtconnect.org web site and those files are no longer there,
as you said.


Reply to this email directly or view it on GitHub
#9 (comment).

  • Will

Sent from my iPhone

@tomsnell
Copy link
Author

xmldata

That was what I was referring to. The comment from 1 hr ago was from the XSD file that was in the schemas folder.

@wsobel
Copy link
Member

wsobel commented Oct 13, 2014

This means it's not finding the schema in the directory references in the
cfg file.

On Monday, October 13, 2014, tomsnell notifications@github.com wrote:

[image: xmldata]
https://cloud.githubusercontent.com/assets/8961923/4546536/63d0c010-4e44-11e4-9c09-bbed9a23fe53.png

That was what I was referring to. The comment from 1 hr ago was from the
XSD file that was in the schemas folder.


Reply to this email directly or view it on GitHub
#9 (comment).

  • Will

Sent from my iPhone

@tomsnell
Copy link
Author

That's another part of my problem is that I am not actually seeing an error in the client -- just no data. I will have to keep searching until I can either find the error I am getting or a better way to ask a question.

@wsobel
Copy link
Member

wsobel commented Oct 13, 2014

You can also add a specific DevicesNamespaces configuration item:

DevicesNamespaces {
  x {
    Urn = urn:mtconnect.org:MTConnectDevices:1.3
    Location = /schemas/MTConnectDevices_1.3.xsd
    Path = ./schemas/MTConnectDevices_1.3.xsd
  }
}

You can set the schema for each type of document. You can also use the 1.0 compatible schemas using the following:

DevicesNamespaces {
  x {
    Urn = urn:mtconnect.org:MTConnectDevices:1.3
    Location = /schemas/MTConnectDevices_1.3.xsd
    Path = ./schemas/MTConnectDevices_1.3_1.0.xsd
  }
}

This is automatically done with the Files declaration if it finds a matching file pattern.

@johnmichaloski
Copy link
Collaborator

Tom,

Maybe you should try the MSXML Object without LINQ (which offers one wrapper for XML and SQL). MSXML won’t parse using an XSD unless you tell it too with an explicit call. MSXML reads a URL but only reports bad XML.

MSXML creates a DOM tree object of the MTConnect Agent output – then you will have to use XPATH.

This will at least work. I have used MSXML and XPATH in a vbs and it works. So it will work in vb.net.
John

From: tomsnell [mailto:notifications@github.com]
Sent: Monday, October 13, 2014 3:25 PM
To: mtconnect/cppagent
Subject: Re: [cppagent] XML Client from Agent (#9)

That's another part of my problem is that I am not actually seeing an error in the client -- just no data. I will have to keep searching until I can either find the error I am getting or a better way to ask a question.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-58941778.

@wsobel wsobel self-assigned this Oct 28, 2014
@wsobel
Copy link
Member

wsobel commented Oct 28, 2014

This is not an agent issue.

@wsobel wsobel closed this as completed Oct 28, 2014
wsobel pushed a commit that referenced this issue Dec 10, 2019
Refactored ChangeObserver to remove dlib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants