3

I'm connecting to an external web service that is implemented using Apache Axis and SOAP 1.2. The web service returns a jagged object array like the one below. Looking at the XML the I have xsi:type="soapenc:Array"

What would be the cleanest/best method of parsing this array in C#2 and C#3 respectively? (I'm specifically interested in C#2 so a C#3 solution would be for interest only.)

- obj  object[] {object[][]}

 -[0]  object {object[]}
  -[0]  object {string}
  -[1]  object {string}

 -[1]  object {object[]}
  -[0]  object {string}
  -[1]  object {bool}

 -[2]  object {object[]}
  -[0]  object {string}
  -[1]  object {object[]}
   -[0]  object {object[][]}
    -[0] object[]
     -[0] object{string}
     -[1] object{string)
2
  • What (code) do you have so far? Commented Jan 25, 2010 at 16:09
  • What do you want to parse it into? You mention xml - do you have some example data with your desired output? Commented Jan 25, 2010 at 16:27

1 Answer 1

1

Not sure on what would be considered the best practice, but this is one way you could do it. Just need to test if the object is an array, if so use its enumerable interface. Recursively check each array item.

    _array = new object[3];
    _result = new StringBuilder();

    //Populate array here

    foreach (object item in _array)
    {
         ParseObject(item);
    }


    private void ParseObject(object value)
    { 
        if (value.GetType().IsArray)
        {
            IEnumerable enumerable = value as IEnumerable;

            foreach (object item in enumerable)
            {                    
                ParseObject(item);
            }                
        }
        else
        {
            _result.Append(value.ToString() + "\n");
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.