Connecting Tech Pros Worldwide Help | Site Map

Client Script XML XPath problem

  #1  
Old November 12th, 2005, 04:12 AM
news.microsoft.com
Guest
 
Posts: n/a
I am using client script to handle some XML stuff with MS XMLDOM
But I ran into a problem in selecting the elements using selectNodes method
The XML looks like:
<root>

........................

<Table>

<PK>3</cls_PK>

<Person_Id>1</cls_LampType_FK>

<ClassName>MV-175</cls_ClassName>

<Department_Id>1</cls_LightType_FK>

</Table>

....................

</root>

and here is the javascript code:

var strNodeSelectionString = "Table[Department_Id = 1 and Person_Id = 1 ]";

var oClassNodesList =
xDocClass.documentElement.selectNodes(strNodeSelec tionString);

The problem here is: the code works fine when I select the element only
based on one child-element value, selectNodes will return 0 elements
whenever I use the structure above.

I checked MS XML4.0 SDK and according the XPath syntax definition the XPath
is perfectly ok.

Any thoughs?



Thanks!!!!!


  #2  
Old November 12th, 2005, 04:12 AM
Martin Honnen
Guest
 
Posts: n/a

re: Client Script XML XPath problem




news.microsoft.com wrote:

[color=blue]
> But I ran into a problem in selecting the elements using selectNodes method
> The XML looks like:
> <root>
>
> .......................
>
> <Table>
>
> <PK>3</cls_PK>
>
> <Person_Id>1</cls_LampType_FK>[/color]
^^^^^^^^^^^^^^^ not well-formed
[color=blue]
> and here is the javascript code:
>
> var strNodeSelectionString = "Table[Department_Id = 1 and Person_Id = 1 ]";
>
> var oClassNodesList =
> xDocClass.documentElement.selectNodes(strNodeSelec tionString);
>
> The problem here is: the code works fine when I select the element only
> based on one child-element value, selectNodes will return 0 elements
> whenever I use the structure above.[/color]

I don't see anything wrong with the XPath expression but what you have
posted as XML is not well-formed at all so it is not possible to tell
whether the XPath expression should match anything or not, we need to
see the real XML.

--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old November 12th, 2005, 04:12 AM
news.microsoft.com
Guest
 
Posts: n/a

re: Client Script XML XPath problem


Sorry for the confusion, the xml looks like:
<?xml version="1.0" standalone="yes"?>

<NewDataSet>

<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

<xs:element name="NewDataSet" msdata:IsDataSet="true">

<xs:complexType>

<xs:choice maxOccurs="unbounded">

<xs:element name="Table">

<xs:complexType>

<xs:sequence>

<xs:element name="cls_PK" type="xs:int" minOccurs="0" />

<xs:element name="cls_LampType_FK" type="xs:int" minOccurs="0" />

<xs:element name="cls_ClassName" type="xs:string" minOccurs="0" />

<xs:element name="cls_Wattage" type="xs:int" minOccurs="0" />

<xs:element name="cls_Lumens" type="xs:string" minOccurs="0" />

<xs:element name="cls_LightType_FK" type="xs:int" minOccurs="0" />

<xs:element name="cls_LampSubType_FK" type="xs:int" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

</xs:element>

</xs:schema>

<Table>

<cls_PK>1</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-100</cls_ClassName>

<cls_Wattage>100</cls_Wattage>

<cls_Lumens>2500~3450</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>2</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-1000</cls_ClassName>

<cls_Wattage>1000</cls_Wattage>

<cls_Lumens>28500~48400</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>3</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-175</cls_ClassName>

<cls_Wattage>175</cls_Wattage>

<cls_Lumens>6800~7600</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>4</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-250</cls_ClassName>

<cls_Wattage>250</cls_Wattage>

<cls_Lumens>8400~10700</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>5</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-400</cls_ClassName>

<cls_Wattage>400</cls_Wattage>

<cls_Lumens>13400~19100</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>6</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-700</cls_ClassName>

<cls_Wattage>700</cls_Wattage>

<cls_Lumens>33,600</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>7</cls_PK>

<cls_LampType_FK>1</cls_LampType_FK>

<cls_ClassName>MV-75</cls_ClassName>

<cls_Wattage>75</cls_Wattage>

<cls_Lumens>2,250</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>8</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-100</cls_ClassName>

<cls_Wattage>100</cls_Wattage>

<cls_Lumens>8,000</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>9</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-150</cls_ClassName>

<cls_Wattage>150</cls_Wattage>

<cls_Lumens>13,800</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>10</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-200</cls_ClassName>

<cls_Wattage>200</cls_Wattage>

<cls_Lumens>19,800</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>11</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-250</cls_ClassName>

<cls_Wattage>250</cls_Wattage>

<cls_Lumens>25,600</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>12</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-310</cls_ClassName>

<cls_Wattage>310</cls_Wattage>

<cls_Lumens>33,300</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>13</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-400</cls_ClassName>

<cls_Wattage>400</cls_Wattage>

<cls_Lumens>45,000</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>14</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-50</cls_ClassName>

<cls_Wattage>50</cls_Wattage>

<cls_Lumens>3,600</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>15</cls_PK>

<cls_LampType_FK>3</cls_LampType_FK>

<cls_ClassName>HPS-70</cls_ClassName>

<cls_Wattage>70</cls_Wattage>

<cls_Lumens>5,450</cls_Lumens>

<cls_LightType_FK>1</cls_LightType_FK>

</Table>

<Table>

<cls_PK>16</cls_PK>

<cls_LampType_FK>6</cls_LampType_FK>

<cls_ClassName>INC12GB</cls_ClassName>

<cls_Wattage>135</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>3</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>17</cls_PK>

<cls_LampType_FK>7</cls_LampType_FK>

<cls_ClassName>INC12GA</cls_ClassName>

<cls_Wattage>135</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>3</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>18</cls_PK>

<cls_LampType_FK>8</cls_LampType_FK>

<cls_ClassName>INC12RB</cls_ClassName>

<cls_Wattage>135</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>3</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>19</cls_PK>

<cls_LampType_FK>9</cls_LampType_FK>

<cls_ClassName>INC12YA</cls_ClassName>

<cls_Wattage>135</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>3</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>20</cls_PK>

<cls_LampType_FK>10</cls_LampType_FK>

<cls_ClassName>INC12YB</cls_ClassName>

<cls_Wattage>135</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>3</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>21</cls_PK>

<cls_LampType_FK>11</cls_LampType_FK>

<cls_ClassName>INC12PED</cls_ClassName>

<cls_Wattage>69</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>3</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>22</cls_PK>

<cls_LampType_FK>6</cls_LampType_FK>

<cls_ClassName>LED12GB</cls_ClassName>

<cls_Wattage>17</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>4</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>23</cls_PK>

<cls_LampType_FK>7</cls_LampType_FK>

<cls_ClassName>LED12GA</cls_ClassName>

<cls_Wattage>5</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>4</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>24</cls_PK>

<cls_LampType_FK>8</cls_LampType_FK>

<cls_ClassName>LED12RB</cls_ClassName>

<cls_Wattage>15</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>4</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>25</cls_PK>

<cls_LampType_FK>9</cls_LampType_FK>

<cls_ClassName>LED12YA</cls_ClassName>

<cls_Wattage>9</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>4</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>26</cls_PK>

<cls_LampType_FK>10</cls_LampType_FK>

<cls_ClassName>LED12YB</cls_ClassName>

<cls_Wattage>32</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>4</cls_LampSubType_FK>

</Table>

<Table>

<cls_PK>27</cls_PK>

<cls_LampType_FK>11</cls_LampType_FK>

<cls_ClassName>LED12PED</cls_ClassName>

<cls_Wattage>10</cls_Wattage>

<cls_LightType_FK>2</cls_LightType_FK>

<cls_LampSubType_FK>4</cls_LampSubType_FK>

</Table>

</NewDataSet>



and Javascript is as follows:



var strNodeSelectionString = "Table[cls_LampSubType = " + strSelectedValue+
" and cls_LampType_FK = " + (nTableRowIndex+6).toString()+ "]";

var oClassNodesList =
xDocClass.documentElement.selectNodes(strNodeSelec tionString);

Thank you in advance.





"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:u4VeyeY$EHA.2192@TK2MSFTNGP14.phx.gbl...[color=blue]
>
>
> news.microsoft.com wrote:
>
>[color=green]
> > But I ran into a problem in selecting the elements using selectNodes[/color][/color]
method[color=blue][color=green]
> > The XML looks like:
> > <root>
> >
> > .......................
> >
> > <Table>
> >
> > <PK>3</cls_PK>
> >
> > <Person_Id>1</cls_LampType_FK>[/color]
> ^^^^^^^^^^^^^^^ not well-formed
>[color=green]
> > and here is the javascript code:
> >
> > var strNodeSelectionString = "Table[Department_Id = 1 and Person_Id =[/color][/color]
1 ]";[color=blue][color=green]
> >
> > var oClassNodesList =
> > xDocClass.documentElement.selectNodes(strNodeSelec tionString);
> >
> > The problem here is: the code works fine when I select the element only
> > based on one child-element value, selectNodes will return 0 elements
> > whenever I use the structure above.[/color]
>
> I don't see anything wrong with the XPath expression but what you have
> posted as XML is not well-formed at all so it is not possible to tell
> whether the XPath expression should match anything or not, we need to
> see the real XML.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/[/color]


  #4  
Old November 12th, 2005, 04:12 AM
Martin Honnen
Guest
 
Posts: n/a

re: Client Script XML XPath problem




news.microsoft.com wrote:
[color=blue]
> the xml looks like:
> <?xml version="1.0" standalone="yes"?>
>
> <NewDataSet>
>
> <xs:schema id="NewDataSet" xmlns=""
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
>[/color]
[color=blue]
> <xs:element name="Table">
>
> <xs:complexType>
>
> <xs:sequence>
>
> <xs:element name="cls_PK" type="xs:int" minOccurs="0" />
>
> <xs:element name="cls_LampType_FK" type="xs:int" minOccurs="0" />
>
> <xs:element name="cls_ClassName" type="xs:string" minOccurs="0" />
>
> <xs:element name="cls_Wattage" type="xs:int" minOccurs="0" />
>
> <xs:element name="cls_Lumens" type="xs:string" minOccurs="0" />
>
> <xs:element name="cls_LightType_FK" type="xs:int" minOccurs="0" />
>
> <xs:element name="cls_LampSubType_FK" type="xs:int" minOccurs="0" />
>
> </xs:sequence>[/color]

Here you have the defined child elements of <Table>, there is
<cls_LampSubType_FK> but below in the XPath you are looking for

[color=blue]
> var strNodeSelectionString = "Table[cls_LampSubType = " + strSelectedValue+
> " and cls_LampType_FK = " + (nTableRowIndex+6).toString()+ "]";[/color]

child elements with name cls_LampSubType and those are not found obviously.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with parsing xml donny answers 1 October 23rd, 2006 06:31 AM
Download the JAVA , .NET and SQL Server interview with answers Jobs answers 2 September 26th, 2006 02:25 PM
Download the JAVA , .NET and SQL Server interview PDF Jobs answers 0 September 17th, 2006 02:05 PM
XML and XSLT question. Please help me out... dennis answers 5 October 28th, 2005 04:55 PM