473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to create Xpath query that retrieve value pairs.

RedSon
5,000 Expert 4TB
Give this XML:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <linear xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.     <linedata>
  4.         <line>
  5.             <rise>253</rise>
  6.             <run>446</run>
  7.         </line>
  8. ...
  9. </close tags...>
  10.  
How do I define an XPath query that will obtain all the "rise"/"run" value pairs under "linedata" in the document?

Xpath "//rise" or Xpath "//run" will give me the rise and run points in the entire document but if I understand properly the order of the rise run pairs is not guaranteed. I need each rise to have it's matching run or my lines will all be screwed up.
Apr 28 '10 #1
4 4816
jkmyoung
2,057 Expert 2GB
What are you using to process the xpath queries? Can you change context and aggregate results, or are you always running the query at the document level?

I'm not sure if you're confusing this with parallel processing, like that in xslt. I think the order should remain the same, but the machine might find the 3rd match before the 2nd match, before concatenating the results.

Also: Can you require that your line element always contains both rise and run elements?
Apr 28 '10 #2
RedSon
5,000 Expert 4TB
My line element should always contain both a rise and a run, but I do not know how to require that in the xsd document. I am using some C/C++ COM code to process this and I believe it does have to be done at the document level. I am running the query against the XMLDOMDocument interface.

I don't know if I can change the context and aggregate the results, my requirement is that for every rise element I have the corresponding run element. And I must have them in the order they are listed in the document.

Do you have a better idea of how to help me?
Apr 28 '10 #3
jkmyoung
2,057 Expert 2GB
If you can, do something like:
Expand|Select|Wrap|Line Numbers
  1. XMLDocument Doc  = new XMLDocument(load document somehow)
  2. XMLNodeList lineNodes = Doc.SelectNodes("//Line")
  3. foreach XMLNode lineNode in lineNodes {
  4.   rise = String2Int(lineNode.SelectSingleNode("rise").value)
  5.   run  = String2Int(lineNode.SelectSingleNode("run").value)
  6.  
  7.   process line with these values.
  8. }
  9.  
If the node doesn't match the schema, then you'll get null errors, which you might have to catch.

Schema: minOccurs and maxOccurs are by default 1. Just by declaring the elements, they should appear (assuming you're validating the input).

Expand|Select|Wrap|Line Numbers
  1. <xs:element name="line" minOccurs="25" maxOccurs="25">
  2.   <xs:complexType>
  3.     <xs:sequence>                    
  4.        <xs:element name="rise" type="xs:integer"/>
  5.        <xs:element name="run" type="xs:integer"/>
  6. ...
  7.  
Apr 28 '10 #4
RedSon
5,000 Expert 4TB
Thanks, you've saved me quite a bit of guess and check.
Apr 28 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jesper Denmark | last post by:
I use Xpath to retrieve nodes in a document like : doc.SelectSingleNode("/properties/layer"); - however this is not very robust as I'm only query on text. What if width='0.200' instead of...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
4
by: johnb41 | last post by:
I need to create a Dataset and datatable from an XML file. The only way I know how to make a Dataset and Datatable, is by using an Access database as my datastore: You know, the usual thing in...
2
by: Jesper Denmark | last post by:
I use Xpath to retrieve nodes in a document like : doc.SelectSingleNode("/properties/layer"); - however this is not very robust as I'm only query on text. What if width='0.200' instead of...
6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
0
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
4
by: cgaden | last post by:
Hi everyone, I have a problem that I've been trying to figure out for a while but I just can't seem to get it right. I have the following XML fragment: <Page ID="x1" Schema="Folder"> -<Page...
2
by: Lonewolf | last post by:
Hi all, please pardon me if this question is too trivial. I have an XML file which stores data in base64. The schema is something like this, <Remokon> <Brand Name="SONY"> <Model Name="Type 1",...
1
by: Gene Kelley | last post by:
This has got to be an easy one, but I'm just not getting it. The following function (below) returns name=value pairs from URL queries (GET). All is working as expected, but I am trying to figure...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.