Comments (10)
I agree. large xml file is too tedious to handle.
from onvif.
a little busy ,but PRs are always welcomed.😊
from onvif.
Hi! I used this code for unmarshalling
type ProfileResponse struct {
XMLName xml.Name
Profiles []onvif.Profile
}
type Body struct {
XMLName xml.Name
GetProfilesResponse ProfileResponse //xml:"GetProfilesResponse"
}
type MyGetProfiles struct {
XMLName xml.Name
Body Body
}
profiles := &MyGetProfiles{}
err = xml.Unmarshal([]byte(resp), profiles)
And for getting profiles:
profiles.Body.GetProfilesResponse.Profiles
from onvif.
if anybody has figured out the unmarshalling of XML responses please let me know , or if someone has started working , we can collaborate...
from onvif.
Any progress on this?
from onvif.
Any progress on this?
I have done this in a kind of hacky way :
This function will query the node from the xml body you want to extract the info from
For example , you do getStreamUri call from dev.CallMethod() and you get a xml resp which contains GetStreamUriResponse
func getXMLNode(xmlBody string, nodeName string) (*xml.Decoder, *xml.StartElement, string) {
xmlBytes := bytes.NewBufferString(xmlBody)
decodedXML := xml.NewDecoder(xmlBytes)
for {
token, err := decodedXML.Token()
if err != nil {
break
}
switch et := token.(type) {
case xml.StartElement:
if et.Name.Local == nodeName {
return decodedXML, &et, ""
}
}
}
return nil, nil, "error in NodeName"
}
and then you just unmarshal into the Response struct
var mGetUsersResp device.GetUsersResponse
bs, _ := ioutil.ReadAll(res.Body)
stringBody := string(bs)
decodedXML, et, errorFunc := getXMLNode(stringBody, "GetStreamUriResponse")
if errorFunc != "" {
log.Printf("%s", errorFunc)
}
if err := decodedXML.DecodeElement(&mStreamUriResp, et); err != nil {
panic(err)
}
from onvif.
Any progress on this?
I have done this in a kind of hacky way :
This function will query the node from the xml body you want to extract the info from
For example , you do getStreamUri call from dev.CallMethod() and you get a xml resp which contains GetStreamUriResponsefunc getXMLNode(xmlBody string, nodeName string) (*xml.Decoder, *xml.StartElement, string) { xmlBytes := bytes.NewBufferString(xmlBody) decodedXML := xml.NewDecoder(xmlBytes) for { token, err := decodedXML.Token() if err != nil { break } switch et := token.(type) { case xml.StartElement: if et.Name.Local == nodeName { return decodedXML, &et, "" } } } return nil, nil, "error in NodeName" }
and then you just unmarshal into the Response struct
var mGetUsersResp device.GetUsersResponse bs, _ := ioutil.ReadAll(res.Body) stringBody := string(bs) decodedXML, et, errorFunc := getXMLNode(stringBody, "GetStreamUriResponse") if errorFunc != "" { log.Printf("%s", errorFunc) } if err := decodedXML.DecodeElement(&mStreamUriResp, et); err != nil { panic(err) }
Works flawlessly, thank you 👍
from onvif.
thanks this does work for string, but integers are set to 0, even if there is a valid response in the body
{{VideoEncoderToken_2 0} {0 0} 0 {0 0 0} {0 } {0 } {{ } 0 0 false} }
And the response
<tt:Name>VideoEncoder_2</tt:Name>
<tt:UseCount>1</tt:UseCount>
<tt:Encoding>H264</tt:Encoding>
<tt:Resolution><tt:Width>640</tt:Width>
<tt:Height>360</tt:Height>
</tt:Resolution>
from onvif.
@cedricve make sure your struct is correct for which you are unmarshalling. You will need to understand the types.
My VideoEncoderConfiguration Struct looks like this :
type VideoEncoderConfiguration struct {
*ConfigurationEntity `json:"ConfigurationEntity"`
Encoding *string `xml:"Encoding" json:",omitempty"`
Resolution *Resolution `xml:"Resolution" json:",omitempty"`
Quality *float64 `xml:"Quality" json:",omitempty"`
RateControl *RateControl `xml:"RateControl" json:",omitempty"`
MPEG4 *MPEG4 `xml:"MPEG4" json:",omitempty"`
H264 *H264 `xml:"H264" json:",omitempty"`
Multicast *Multicast `xml:"Multicast" json:",omitempty"`
SessionTimeout *string `xml:"SessionTimeout" json:",omitempty"`
}
also fields like Resolution point to another struct which is like this:
type Resolution struct {
Width *xsd.Int `xml:"Width"`
Height *xsd.Int `xml:"Height"`
}
xsd Int is basically type Int int32
these structs are autogenerated from ONVIF's xsd
from onvif.
Hi, do we have concrete solution on this issue (other than the solution mentioned above) or anybody working on this and planning to release in near future.
from onvif.
Related Issues (20)
- Onvif Profile M supported?
- How did you convert onvif XSD to all these structs
- Some structures are incorrectly defined
- memery leak many socket not close
- Code consistency
- onvif version
- why Authenticate function has been deleted? HOT 1
- Media structs are prefixed with onvif: HOT 9
- ptz / types / GetPresetsResponse - Profiles field should be a list HOT 2
- How do I set the connection password for the discovered device
- Incorret schema for onvif.ptz.GetPresetsResponse
- onvif PlayBack
- Can this act as an onvif server? HOT 2
- Is possible to make multicast in different subnet?
- Unable to set IP Address
- Subscribe response isn't correct when status code is 500
- GetProfile is not working in some cameras. HOT 3
- deviceIO package missing
- Support for Profile T (advanced streaming capabilities) HOT 1
- NewDevice succeeds on non camera devices HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onvif.