locked
Does it really support ReadElementString() in metro mode?

    Question

  • I would like to read a xml file by XmlReader and get the value of <ID> directly.

    <Playlist>
      <Ver>1.0</Ver>
      <ID>USER</ID>
    </Playlist>

    I have studied the sample code "IXmlReader and IXmlWriter XML data readwrite sample" from msdn website

    and try to use ReadElementString() to get the value of <ID> directly.

    ComPtr<IXmlReader> spReader;

    Unfortunately, I can not find this funtion by spReader->ReadElementString().

    Anyone knows how to use ReadElementString()?  or any other way ?

    Thanks a lot.

    Wednesday, July 25, 2012 12:31 PM

Answers

  • Hi,

    There is no ReadElementString function in IXmlReader interface.
    Generally speaking, we call spReader->Read(&nodeType) function to read the node and value in xml file.

    The nodeType instruct the nodetype of current element. If we want to get the value in that element,  it value type is XmlNodeType_Text, then we call spReader->GetValue function to get the value.
     like this

      case XmlNodeType_Text:
      if (FAILED(hr = pReader->GetValue(&pwszValue, NULL))){
      wprintf(L"Error getting value, error is %08.8lx", hr);
      return -1;
      }
      wprintf(L"Text: %s\n", pwszValue);
      break;
    
    

    Please follow the sample codes in this document.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms752878(v=vs.85).aspx


    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Mandy1205 Tuesday, July 31, 2012 1:54 AM
    Thursday, July 26, 2012 10:17 AM

All replies

  • Could you paste a link to the sample you studied please?

    Thanks!


    David Lamb

    Thursday, July 26, 2012 12:08 AM
    Moderator
  • Hi,

    There is no ReadElementString function in IXmlReader interface.
    Generally speaking, we call spReader->Read(&nodeType) function to read the node and value in xml file.

    The nodeType instruct the nodetype of current element. If we want to get the value in that element,  it value type is XmlNodeType_Text, then we call spReader->GetValue function to get the value.
     like this

      case XmlNodeType_Text:
      if (FAILED(hr = pReader->GetValue(&pwszValue, NULL))){
      wprintf(L"Error getting value, error is %08.8lx", hr);
      return -1;
      }
      wprintf(L"Text: %s\n", pwszValue);
      break;
    
    

    Please follow the sample codes in this document.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms752878(v=vs.85).aspx


    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Mandy1205 Tuesday, July 31, 2012 1:54 AM
    Thursday, July 26, 2012 10:17 AM
  • Hello Jesse:

    It's the only way to get the value of a element?

    That means I just want to get the value of a element, I need to read the whole file.

    Here are the example of CMarkup parser.

    <Media>
    <Ver>1.0<Ver>
    <ID>1<ID>
    </Media>

    CMarkup xmldoc;
    if(xmldoc.FindElem(_T("Media")){
        if(xmldoc.FindChildElem(_T("ID")))
            version = xmldoc.GetChildData();
    }

    It seems that I can just read ID directly, not read the whole file.

    Thursday, July 26, 2012 11:22 AM
  • Based on the document, there is only one way to get value from IXmlReader interface using GetValue.

     

    Cmarkup is third-part library, we not sure it supported in metro.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 30, 2012 7:14 AM
  • Thank you so much.
    Tuesday, July 31, 2012 1:56 AM