Results 1 to 9 of 9

Thread: XML stumper :(

  1. #1

    Thread Starter
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362

    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.

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.

  3. #3

    Thread Starter
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  5. #5

    Thread Starter
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  7. #7

    Thread Starter
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Right so then unless I'm totally missing the plot here ;

    VB Code:
    1. Open "c:\a.xml" For Input As #1
    2.         MsgBox "Starting position of node : " & InStr(Input(LOF(1), 1), "<node2>")
    3.     Close #1
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9

    Thread Starter
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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
  •  



Click Here to Expand Forum to Full Width