This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > February 2005 > editing xml document help needed!!
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
editing xml document help needed!!
|
|
| GeorgeAtkins 2005-02-14, 4:22 am |
| Using VB.NET, VS2003, XML. I apologize for the length of this request.
I've written before and received advise pointing to several articles.
Frankly, I'm still confused and need more help!
My request might be a little different than what XML procedures appear to be
directed towards (ie, wholesale transformations or mass updates). What I need
to do is to selectively locate book titles and update information in a
related field.
Here is a simplified view of the XML file. It represents data for two
specific books. The document root is <mrcbfile>. The node for specific books
(with attribute) is <mrcb format-type="bd">. Each book node has several
childnodes, although I've only included a few for this example (capitalized
nodes are the important ones)
<mrcbfile>
<mrcb format-type="bd">
<mrcb-control-fields>
<mrcb008-bk>
<mrcb008-bk-00-05 value="020718"/>
</mrcb008-bk>
</mrcb-control-fields>
<MRCB-TITLE-AND-TITLE-RELATED>
<mrcb245 i1="i1-1" i2="i2-4">
<mrcb245-a>The fat girl</mrcb245-a>
<mrcb245-c>Marilyn Sachs.</mrcb245-c>
</mrcb245>
</mrcb-title-and-title-related>
<MRCB-NOTES>
<mrcb520 i1="i1-blank" i2="i2-blank">
<mrcb520-a>Jeff, a high school senior, becomes obsessed with creating a
new, beautiful, person.</mrcb520-a>
</mrcb520>
</mrcb-notes>
<MRCB-NOTES>
<mrcb596 i1="i1-blank" i2="i2-blank">
<mrcb596-a>1</mrcb596-a>
</mrcb596>
</mrcb-notes>
</mrcb> <mrcb format-type="bd">
<mrcb-control-fields>
<mrcb008-bk>
<mrcb008-bk-00-05 value="020718"/>
</mrcb008-bk>
</mrcb-control-fields>
<MRCB-TITLE-AND-TITLE-RELATED>
<MRCB245 i1="i1-1" i2="i2-2">
<MRCB245-A>A pocket full of seeds </mrcb245-a>
</mrcb245>
</mrcb-title-and-title-related>
<MRCB-NOTES>
<mrcb520 i1="i1-blank" i2="i2-blank">
<mrcb520-a>Nicole's parents thought they would have enough time to
escape from the Nazis.</mrcb520-a>
</mrcb520>
</mrcb-notes>
<MRCB-NOTES>
<MRCB590 i1="i1-blank" i2="i2-blank">
<MRCB590-A>Quiz owned by: FOREST, NEILL</mrcb590-a>
</mrcb590>
<MRCB590 i1="i1-blank" i2="i2-blank">
<mrcb590-a>Quiz owned by: FOREST, NEILL</mrcb590-a>
</mrcb590>
</mrcb>
</mrcbfile>
What I need to do:
1. Go to the first book (/<mrcb> ) and check the book's title (at
/<mrcb>/<mrcb-title-and-title-related>/mrcb245/mrcb245-a)
2. If the title matches my compare string, I need to look for the
<mrcb590>/<mrcb590-a> descendant of the current book ("Quiz owned by...") and
add a name to the end of the list. Not all books have the 590 tag.
3. Repeat steps 1 and 2 for every other book in the file.
4. At the end, save the edited XML data into a new file .
PROBLEMS
1. I've tried using xpath and DOM, building nodelists to look into. But when
I build a reference to the book node, I get stuck on how to navigate through
each child and "grand-child" to find the title and notes descendants of that
node so I can change the Notes text. I've tried to create nexted for each
loops, based on additional nodelists set to deeper levels, but they don't
seem to be connected at all.
2. I think that, once I locate the first node (the first book), that I need
to clone the node so that I can navigate through it without changing the
original current node. But I'm stuck on how this all should be coded.
REQUEST
I'm frustrated and desperate. Can somebody give me a bit of (pseudo or real
)code to show how the best way to navigate through the books <mrcb>, look for
a specific book title <mrcb245-a> and if found, append/edit text to any (and
all) 590-a text descendants ("QUiz owned by...") of that node. I've read
every articles I can find on xml, xpath, doc, navigator, etc.
Thanks a million in advance!
George
| |
| GeorgeAtkins 2005-02-14, 6:36 pm |
| Sorry. I may have posted to the wrong group; I'll repost at dotnet.xml
George
"GeorgeAtkins" wrote:
> Using VB.NET, VS2003, XML. I apologize for the length of this request.
>
> I've written before and received advise pointing to several articles.
> Frankly, I'm still confused and need more help!
>
> My request might be a little different than what XML procedures appear to be
> directed towards (ie, wholesale transformations or mass updates). What I need
> to do is to selectively locate book titles and update information in a
> related field.
>
> Here is a simplified view of the XML file. It represents data for two
> specific books. The document root is <mrcbfile>. The node for specific books
> (with attribute) is <mrcb format-type="bd">. Each book node has several
> childnodes, although I've only included a few for this example (capitalized
> nodes are the important ones)
>
> <mrcbfile>
> <mrcb format-type="bd">
> <mrcb-control-fields>
> <mrcb008-bk>
> <mrcb008-bk-00-05 value="020718"/>
> </mrcb008-bk>
> </mrcb-control-fields>
> <MRCB-TITLE-AND-TITLE-RELATED>
> <mrcb245 i1="i1-1" i2="i2-4">
> <mrcb245-a>The fat girl</mrcb245-a>
> <mrcb245-c>Marilyn Sachs.</mrcb245-c>
> </mrcb245>
> </mrcb-title-and-title-related>
> <MRCB-NOTES>
> <mrcb520 i1="i1-blank" i2="i2-blank">
> <mrcb520-a>Jeff, a high school senior, becomes obsessed with creating a
> new, beautiful, person.</mrcb520-a>
> </mrcb520>
> </mrcb-notes>
> <MRCB-NOTES>
> <mrcb596 i1="i1-blank" i2="i2-blank">
> <mrcb596-a>1</mrcb596-a>
> </mrcb596>
> </mrcb-notes>
>
> </mrcb> <mrcb format-type="bd">
> <mrcb-control-fields>
> <mrcb008-bk>
> <mrcb008-bk-00-05 value="020718"/>
> </mrcb008-bk>
> </mrcb-control-fields>
> <MRCB-TITLE-AND-TITLE-RELATED>
> <MRCB245 i1="i1-1" i2="i2-2">
> <MRCB245-A>A pocket full of seeds </mrcb245-a>
> </mrcb245>
> </mrcb-title-and-title-related>
> <MRCB-NOTES>
> <mrcb520 i1="i1-blank" i2="i2-blank">
> <mrcb520-a>Nicole's parents thought they would have enough time to
> escape from the Nazis.</mrcb520-a>
> </mrcb520>
> </mrcb-notes>
> <MRCB-NOTES>
> <MRCB590 i1="i1-blank" i2="i2-blank">
> <MRCB590-A>Quiz owned by: FOREST, NEILL</mrcb590-a>
> </mrcb590>
> <MRCB590 i1="i1-blank" i2="i2-blank">
> <mrcb590-a>Quiz owned by: FOREST, NEILL</mrcb590-a>
> </mrcb590>
> </mrcb>
> </mrcbfile>
>
>
> What I need to do:
> 1. Go to the first book (/<mrcb> ) and check the book's title (at
> /<mrcb>/<mrcb-title-and-title-related>/mrcb245/mrcb245-a)
> 2. If the title matches my compare string, I need to look for the
> <mrcb590>/<mrcb590-a> descendant of the current book ("Quiz owned by...") and
> add a name to the end of the list. Not all books have the 590 tag.
> 3. Repeat steps 1 and 2 for every other book in the file.
> 4. At the end, save the edited XML data into a new file .
>
> PROBLEMS
> 1. I've tried using xpath and DOM, building nodelists to look into. But when
> I build a reference to the book node, I get stuck on how to navigate through
> each child and "grand-child" to find the title and notes descendants of that
> node so I can change the Notes text. I've tried to create nexted for each
> loops, based on additional nodelists set to deeper levels, but they don't
> seem to be connected at all.
> 2. I think that, once I locate the first node (the first book), that I need
> to clone the node so that I can navigate through it without changing the
> original current node. But I'm stuck on how this all should be coded.
>
> REQUEST
> I'm frustrated and desperate. Can somebody give me a bit of (pseudo or real
> )code to show how the best way to navigate through the books <mrcb>, look for
> a specific book title <mrcb245-a> and if found, append/edit text to any (and
> all) 590-a text descendants ("QUiz owned by...") of that node. I've read
> every articles I can find on xml, xpath, doc, navigator, etc.
>
> Thanks a million in advance!
> George
| |
| gadrin7@aol.com 2005-02-14, 11:17 pm |
| ; your XML was too messed up to use...
;<root>
; <mainNode>
; <title>Title of Book 1</title>
; <author>Author of Book 1</author>
; </mainNode>
; <mainNode>
; <title>Title of Book 2</title>
; <author>Author of Book 2</author>
; </mainNode>
; <mainNode>
; <title>Title of Book 3</title>
; <author>Author of Book 3</author>
; </mainNode>
;</root>
; this is similar to vbscript...
; the message() functions are equivalent to vbs MSGBOX...
xmldoc = objectopen("Microsoft.XMLDOM")
xmldoc.async = @false
xmldoc.load("c:\jay\xml\test.xml")
err = xmlDoc.parseError
if err.errorCode then gosub ShowParseErrors
;message("Debug", xmlDoc.xml)
; find the mainNode for Book 2
mNode = xmldoc.selectsinglenode("//mainNode[title='Title of Book 2']")
message("debug", mNode.xml)
; now get the title from the mainNode...
; use the . in XPATH to represent the current node context...
Title = mNode.selectsinglenode(".//title")
Author = mNode.selectsinglenode(".//author")
message(Title.text, Author.text)
exit
:ShowParseErrors
message(err.errorCode, err.reason)
message(strcat("at line ", err.line, ", character ", err.linepos),
err.srcText)
Hope this helps...
| |
| GeorgeAtkins 2005-02-15, 4:21 am |
| Thanks for the reply! Sorry 'bout the XML paste; it's the way it pasted in
and it has several levels/nodes in it. I'll work on adapting your example to
my XML format. Thanks again.
George
"gadrin7@aol.com" wrote:
> ; your XML was too messed up to use...
>
> ;<root>
> ; <mainNode>
> ; <title>Title of Book 1</title>
> ; <author>Author of Book 1</author>
> ; </mainNode>
> ; <mainNode>
> ; <title>Title of Book 2</title>
> ; <author>Author of Book 2</author>
> ; </mainNode>
> ; <mainNode>
> ; <title>Title of Book 3</title>
> ; <author>Author of Book 3</author>
> ; </mainNode>
> ;</root>
>
> ; this is similar to vbscript...
> ; the message() functions are equivalent to vbs MSGBOX...
>
> xmldoc = objectopen("Microsoft.XMLDOM")
> xmldoc.async = @false
> xmldoc.load("c:\jay\xml\test.xml")
>
> err = xmlDoc.parseError
> if err.errorCode then gosub ShowParseErrors
>
> ;message("Debug", xmlDoc.xml)
>
> ; find the mainNode for Book 2
> mNode = xmldoc.selectsinglenode("//mainNode[title='Title of Book 2']")
> message("debug", mNode.xml)
>
> ; now get the title from the mainNode...
> ; use the . in XPATH to represent the current node context...
>
> Title = mNode.selectsinglenode(".//title")
> Author = mNode.selectsinglenode(".//author")
>
> message(Title.text, Author.text)
>
> exit
>
> :ShowParseErrors
>
> message(err.errorCode, err.reason)
> message(strcat("at line ", err.line, ", character ", err.linepos),
> err.srcText)
>
>
> Hope this helps...
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|