We help IT Professionals succeed at work.

XML inside XML

EDDYKT
EDDYKT asked
on
1,406 Views
Last Modified: 2008-01-09
I have the following xml (just make it up, the idea is to show xml inside the xml)

<?xml version="1.0" encoding="utf-8"?>
<GetResult>
    <?xml version="1.0" encoding="utf-8"?><GetResultString>1.1</GetResultString>
</GetResult>

I use DOM to load the above string and get an error
dim s as string
Dim doc As New MSXML2.DOMDocument

s = "<?xml version=""1.0"" encoding=""utf-8""?>"
s = s & "<GetResult>"
s = s & "<?xml version=""1.0"" encoding=""utf-8""?>"
s = s & "<GetResultString>"
s = s & "1.1"
s = s & "</GetResultString>"
s = s & "</GetResult>"
doc.async = False
doc.validateOnParse = False
doc.loadXML s            ' where s is the above string

The error is

?doc.parseError.errorCode
-1072896681
?doc.parseError.reason
Invalid xml declaration.

I would like to use DOM to get the string of the inner xml and set it in another DOM to parse data
What can i make it work?

Don't tell me to use instr to parse data, the about is just an example. The actual xml is different.

VB6 and sp6
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
The xml string comes back from web server and i cannot do anything on it.

That's the problem, It's like a chicken and egg problem

I need to parse it with dom to get the xml string. not encode it before to pass it to dom

8->
Hmm... ok, that comlicates things somewhat :)

Can you be certain that the response is always like

<?xml version="1.0" encoding="utf-8"?>
<GetResult>
[THE PART YOU ARE REALLY INTERESTED IN]
</GetResult>

...or is there a possibility that it will contain something totally different?

If it is, you could just take the first, second and last line away (in any way you see fit) and handle what is left as the actual result. I'm not entirely certain if this falls under "use instr to parse data", but I decided to give it a go nonetheless ;)

Author

Commented:
Again that is example of the test xml

Author

Commented:
the actual part may include SOAP envlope that you may not want to know
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.