+ Reply to Thread
Results 1 to 2 of 2

XPath.SetValue question

Hybrid View

  1. #1
    Registered User
    Join Date
    11-05-2010
    Location
    san diego, ca
    MS-Off Ver
    Excel 2007
    Posts
    2

    XPath.SetValue question

    I’m using the following code to map elements to a list:

    Sub GetDVA7()
    
        Dim oMyMap As XmlMap
        Dim strXPath As String
        Dim oMyList As ListObject
        Dim oMyNewColumn As ListColumn
        
        'Add a schema map
        ThisWorkbook.XmlMaps.Add (ThisWorkbook.Path & "\DVarchiveA2_replayInfo9.xsd")
        
        ' Idenfity the target schema map.
        Set oMyMap = ThisWorkbook.XmlMaps("DVARCHIVE_Map")
        
        Range("A1").Select
        
        ' Create a new list.
        Set oMyList = ActiveSheet.ListObjects.Add
        Set oMyNewColumn = oMyList.ListColumns(1)
        
        ' Specify the first element to map.
        strXPath = "/DVARCHIVE/@ACCESS"
        ' Map the element.
        oMyNewColumn.XPath.SetValue oMyMap, strXPath
        
        ' Add a column to the list.
        Set oMyNewColumn = oMyList.ListColumns.Add
        
        ' Specify the next element to map.
        strXPath = "/DVARCHIVE/@IP_PORT"
        ' Map the element.
        oMyNewColumn.XPath.SetValue oMyMap, strXPath
        
    End Sub
    This is the schema:

    <?xml version='1.0' encoding='UTF-16'?>
    <!-- Created from XmlMap.Name: DVARCHIVE_Map -->
    <!-- XmlMap.DataBinding.SourceUrl: C:\DVarchive_replayInfo.xml -->
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element  name="DVARCHIVE">
         <xsd:complexType>
            <xsd:attribute name="ACCESS"  type="xsd:string"/>
            <xsd:attribute name="IP_PORT"  type="xsd:integer"/>
         </xsd:complexType>
      </xsd:element>
    </xsd:schema>
    my code works fine for the first element: type="xsd:string" but for the second element: type="xsd:integer" I get a warning:

    The data you are attempting to map contains formatting that is incompatible with the format specified in the worksheet.
    (with three choices) "Use existing formatting," "Match element data type," or "Cancel."

    I’m starting with a new blank sheet that is formatted by default to “General”.

    If I map the integer element to the first column and the string element to the second column it works fine.

    can someone tell me what causes the warning and how to fix it.

    Using Excel 2007

  2. #2
    Registered User
    Join Date
    11-05-2010
    Location
    san diego, ca
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: XPath.SetValue question

    I did some experimenting and found that formatting the header row first fixed the problem.

    Range("A1").Select 
    ActiveCell.EntireRow.Select 
    Selection.NumberFormat = "General" 
    ActiveCell.Select

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1