ohmae / mmupnp

Universal Plug and Play (UPnP) ControlPoint library for Java/Kotlin
MIT License
50 stars 11 forks source link

[Question] Device.getValue(“av_X_FOO_DeviceIfno”) can’t return that block, return null. #38

Closed yamatakau08 closed 2 years ago

yamatakau08 commented 2 years ago

I got to find Device.description returns the xml string and confirmed that api returns whole xml string,

To get the \...</av:X_FOO_DeviceInfo> block in the following xml which Device.description returns, I called Device.getValue(“av:X_FOO_DeviceInfo”) , but returns NULL .

Is there any way to get \<av:X_FOO_DeviceInfo”> block or \ TWO blocks directly with supported API of mmupnp?

OR should I parse that with any XML parse library by myself?

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:dlna="urn:schemas-dlna-org:device-1-0" xmlns:av="urn:schemas-foo-com:av">
  ...
  <device>
    ...
    <av:X_FOO_DeviceInfo>
      <av:X_FOO_Version>1,2</av:X_FOO_Version>
      <av:X_FOO_v1Info>
        <av:X_FOO_Port>12345</av:X_FOO_Port>
      </av:X_FOO_v1Info>
      <av:X_FOO_v2Info>
        <av:X_FOO_Port>123456</av:X_FOO_Port>
      </av:X_FOO_v2Info>
    </av:X_FOO_DeviceInfo>
  </device>
</root>
ohmae commented 2 years ago

Those tags are not a UPnP standard, an extension of the device manufacturer. If it has the same structure as the standard tag, getValue can get the value, but apparently the structure is different, so it is impossible. By the way, your getValue argument is wrong. You should delete the namespace or specify the namespace URI. getValue("X_FOO_DeviceInfo") or getValue("urn:schemas-foo-com:av", "X_FOO_DeviceInfo") However, since it returns textcontent, I think the return value is blank.

yamatakau08 commented 2 years ago

I appreciate your strong support.

I revise the code to Device.getValue(“X_FOO_DeviceInfo”) you suggested from Device.getValue(“av:X_FOO_DeviceInfo”) It returns the following data seems to be what I wanted.

 2022-01-08 16:57:40.945 26881-26881/com.example.myaudioremote I/X_FOO_DeviceInfo:       1,2

             12345

             123456

But getValue("urn:schemas-foo-com:av", "X_FOO_DeviceInfo") has an error about 2nd argument Android Studio pointed out in source window.

yamatakau08 commented 2 years ago

Since I get the value what I want, I close this question.