|
-
Nov 15th, 2001, 12:09 PM
#1
Thread Starter
Hyperactive Member
XML stumper :(
Umm, try this one on for size...
Given and XML document (MSXML say), if when iterating thru the Document, how can one find the character (starting character) position of any given Node with in the Document (source xml), white space and all?
For example, if the document looks something like this:
Code:
<node1>
---tab--- <node2>
---tab--- ---tab--- <node3/>
---tab--- </node2>
</node1>
and while iterating thru the DOM you come across node2, who's xml is
Code:
<node2>
---tab--- <node3/>
</node2>
how do you find the character position of the "<" in "<node2>" within the entire document ?
A simple Find won't work because if you search for the node2 xml (with one tab) in the doc xml, you won't find it because node2 in the doc contains two tabs.
Anyone got any ideas?
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 15th, 2001, 01:05 PM
#2
Black Cat
A DOM parser shouldn't care about whitespace, so you'd really need to parse it as raw text.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Nov 16th, 2001, 04:04 AM
#3
Thread Starter
Hyperactive Member
I really didn't want to have to right my own (has to include CDATA etc), umm...
Saying the DOM parser shouldn't care about white space is correct, but it can preserve it, and in this case, white space is included (presented) with each node. So internaly, there must be some reference (index) of a given node to it's owner doc.
Question is, how to get at it?
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 16th, 2001, 04:08 AM
#4
Retired VBF Adm1nistrator
Well d'ya know what you could do right... you could load the entire file into a String variable, use Replace() to replace all the tabs with "", then you'd have a nice flat file
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 16th, 2001, 04:18 AM
#5
Thread Starter
Hyperactive Member
plendy, are you joking?
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 16th, 2001, 04:20 AM
#6
Retired VBF Adm1nistrator
Nah Im serious. Foget about it being an XML document, but rather just any text document. And you just want to find the position of a particular string of text in the file...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 16th, 2001, 04:25 AM
#7
Thread Starter
Hyperactive Member
the whole point of the exercise is to find the relaitve position in the full (tabs 'n' all) document.
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 16th, 2001, 04:51 AM
#8
Retired VBF Adm1nistrator
Right so then unless I'm totally missing the plot here ;
VB Code:
Open "c:\a.xml" For Input As #1
MsgBox "Starting position of node : " & InStr(Input(LOF(1), 1), "<node2>")
Close #1
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 16th, 2001, 05:31 AM
#9
Thread Starter
Hyperactive Member
Mate, what on earth are you on about?
use this example
Code:
<node1>
---tab--- <node2> <node3/>
---tab--- ---tab--- <node4/>
---tab--- </node2>AndHereIsSomeCDATA</node1>
So, how can we tell the original character position of say <node3> or the CDATA element?
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|