Workaround for GetChildIntValue 32-bit Limitation

The key point is that GetChildIntValue returns a 32-bit signed integer, which imposes strict limits on what values it can represent.


1) 32-bit signed integer limits

A 32-bit signed integer uses one bit for the sign and 31 bits for the value:

  • Minimum: −2,147,483,648 (−2³¹)
  • Maximum: +2,147,483,647 (2³¹ − 1)

So any XML value outside this range cannot be represented correctly.


2) What happens if the XML value is too large?

If the integer in the XML exceeds this range (for example: 5000000000), then:

  • It cannot fit in a 32-bit signed integer.
  • The result returned by GetChildIntValue will be incorrect (overflow, truncation, or undefined depending on language/runtime).
  • No automatic promotion to 64-bit occurs — the method is strictly 32-bit.

3) Correct approach for large integers

For values that might exceed 32-bit limits, you should:

  1. Retrieve the value as a string
    string s = xml.GetChildContent("SomeTag");
    
  2. Convert to a 64-bit integer using your language
    Examples:

    C#:

    long val = long.Parse(s);
    
    C++:
    long long val = std::stoll(s);
    
    Java:
    long val = Long.parseLong(s);
    
    VB6 / VBA (via helper or library):
    • Use a library or custom conversion since native 64-bit support is limited.

4) Why this approach is better

  • Avoids overflow and data corruption
  • Preserves full numeric precision
  • Works for arbitrarily large integers (you could even use big integer types if needed)

5) Practical rule of thumb

  • Use GetChildIntValue only when you are certain the value fits in:
    −2,147,483,648 to +2,147,483,647
    
  • Otherwise:
    • Use GetChildContent
    • Convert explicitly to 64-bit (or larger) in your application

This pattern is especially important when working with:

  • IDs (database keys, timestamps)
  • Financial values
  • Counters or file sizes

Anything that might naturally exceed 32-bit range should never be retrieved directly as an int.