[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1337
  • Last Modified:

XML inside XML

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
0
EDDYKT
Asked:
EDDYKT
  • 3
  • 2
1 Solution
 
DiscoNovaCommented:
If you wish to handle the contents of the (outern) GetResult as a string, you will need to handle it as a string.

This means that the special characters of XML ("less than sign", "greater than sign", and the kind) will need to be encoded according to the schema you're using. How they should be encoded depends on the DTD, but usually DTDs have entities for the mentioned signs like &lt; &gt; or something similar.

Furthermore, before you pass the contents of the string to the next DOMDocument, you of course need to decode the string (unless this gets done automatically - you need to try it to find out (or read the manuals)).
0
 
EDDYKTAuthor 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->
0
 
DiscoNovaCommented:
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 ;)
0
 
EDDYKTAuthor Commented:
Again that is example of the test xml
0
 
EDDYKTAuthor Commented:
the actual part may include SOAP envlope that you may not want to know
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now