Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / November 2005

Tip: Looking for answers? Try searching our database.

Xpath newb question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CHRISTOPHER FRAZIER - 22 Nov 2005 01:57 GMT
I'm trying to integrate an xml document into a vba application, and I'm pretty new to xml and xpath.  I have the following xml document:

<Chart>
   <Account>1000.10
       <Department>10</Department>
       <MapNo>111</MapNo>
       <Amount>1234.59</Amount>
   </Account>
   ....plus a bunch of similar <Account> elements
</Chart>

I can use //Account[Department='10'] to return all account nodes with a '10' department, but I can't use Chart[Account='1000.10'] to return a particular account.  I figure I can restructure my xml document to be either

<Account Number="1000.10">

or

<Account>
   <Number>1000.10</Number>
</Account>

But I don't understand why the first format didn't work.  Can anyone explain this to me?

Thanks,

CHRISTOPHER FRAZIER
Truong Hong Thi - 22 Nov 2005 04:33 GMT
Hi Christopher,

The thing that makes your xpath query does not work is the new line
character after 1000.10.
The best cure is using XPath "normalize-space" function, which trim
white spaces out of the string. Your query then would look like:
/Chart[normalize-space(Account)='1000.10']

Thi
Truong Hong Thi - 22 Nov 2005 04:47 GMT
I am sorry. That only works if the element has no children, or contents
of children (Department, MapNo, Amount) are empty. When you specify:
[Account='1000.10'], it mean that the concatenation of the text of
"Account" and all of its children's text is '1000.10'.

In your case, to make it work, you should select the first text node
that is child of "Account", and compare it to '1000.10'. Something like
this:
/Chart[normalize-space(Account/text()[1])='10']

Regards,
Thi
viditmittal@gmail.com - 25 Nov 2005 05:07 GMT
try the following XPath expression to get the result

.selectSingleNode("/Chart/Account[.='1000.10']")

i hope this helps

regards
VIDIT

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.