EDN Admin
Well-known member
I have the XML:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; root<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; table <span style="color:Red; xmlns:h<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/TR/html4/<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; name <span style="color:Red; atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; tanya<span style="color:Black; "<span style="color:Blue; >African Coffee Table<span style="color:Blue; </<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; length<span style="color:Blue; >120<span style="color:Blue; </<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; length<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; attri<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; duke<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; chair<span style="color:Blue; >dave<span style="color:Blue; </<span style="color:#A31515; chair<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table <span style="color:Red; xmlns:f<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3schools.com/furniture<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name <span style="color:Red; f:atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; shirley<span style="color:Black; "<span style="color:Blue; >African Coffee Table<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; width<span style="color:Blue; >80<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; width<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; xmlns<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3schools.com/dave<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; name <span style="color:Red; atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; winter<span style="color:Black; "<span style="color:Blue; >tanya<span style="color:Blue; </<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table <span style="color:Red; xmlns:f<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3schools.com/again<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name <span style="color:Red; f:atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zoe<span style="color:Black; "<span style="color:Blue; >cody<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; root<span style="color:Blue; >
[/code]
and I need to write an XPath that gets the 2nd f:table. So I tried the following, but it didnt work:
<div style="color:Black;background-color:White; <pre>
XmlNamespaceManager context = <span style="color:Blue; new XmlNamespaceManager(xmlDocument.NameTable);
context.AddNamespace(<span style="color:#A31515; "h", <span style="color:#A31515; "http://www.w3.org/TR/html4/");
context.AddNamespace(<span style="color:#A31515; "f", <span style="color:#A31515; "http://www.w3schools.com/furniture");
context.AddNamespace(<span style="color:#A31515; "def", <span style="color:#A31515; "http://www.w3schools.com/dave");
context.AddNamespace(<span style="color:#A31515; "f1", <span style="color:#A31515; "http://www.w3schools.com/again");
[/code]
And then tried a select of "/root/f1:table" and it failed telling me that f1 does not exist. I have to do a different prefix to differentiate between the two uses of the f prefix.
Any ideas?
thanks - dave
ps - A customer of ours recycles prefixes in their XML so we have to support this. A redesign of their XML is not acceptable to them. <hr class="sig Very funny video - http://blogs.windwardreports.com/davidt/2010/02/reporting-as-a-metaphor.html
Whats your Metaphor?
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; root<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; table <span style="color:Red; xmlns:h<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/TR/html4/<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; name <span style="color:Red; atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; tanya<span style="color:Black; "<span style="color:Blue; >African Coffee Table<span style="color:Blue; </<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; length<span style="color:Blue; >120<span style="color:Blue; </<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; length<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; h<span style="color:Blue; :<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; attri<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; duke<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; chair<span style="color:Blue; >dave<span style="color:Blue; </<span style="color:#A31515; chair<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table <span style="color:Red; xmlns:f<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3schools.com/furniture<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name <span style="color:Red; f:atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; shirley<span style="color:Black; "<span style="color:Blue; >African Coffee Table<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; width<span style="color:Blue; >80<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; width<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; xmlns<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3schools.com/dave<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; name <span style="color:Red; atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; winter<span style="color:Black; "<span style="color:Blue; >tanya<span style="color:Blue; </<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table <span style="color:Red; xmlns:f<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3schools.com/again<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name <span style="color:Red; f:atr<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zoe<span style="color:Black; "<span style="color:Blue; >cody<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; name<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; f<span style="color:Blue; :<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; root<span style="color:Blue; >
[/code]
and I need to write an XPath that gets the 2nd f:table. So I tried the following, but it didnt work:
<div style="color:Black;background-color:White; <pre>
XmlNamespaceManager context = <span style="color:Blue; new XmlNamespaceManager(xmlDocument.NameTable);
context.AddNamespace(<span style="color:#A31515; "h", <span style="color:#A31515; "http://www.w3.org/TR/html4/");
context.AddNamespace(<span style="color:#A31515; "f", <span style="color:#A31515; "http://www.w3schools.com/furniture");
context.AddNamespace(<span style="color:#A31515; "def", <span style="color:#A31515; "http://www.w3schools.com/dave");
context.AddNamespace(<span style="color:#A31515; "f1", <span style="color:#A31515; "http://www.w3schools.com/again");
[/code]
And then tried a select of "/root/f1:table" and it failed telling me that f1 does not exist. I have to do a different prefix to differentiate between the two uses of the f prefix.
Any ideas?
thanks - dave
ps - A customer of ours recycles prefixes in their XML so we have to support this. A redesign of their XML is not acceptable to them. <hr class="sig Very funny video - http://blogs.windwardreports.com/davidt/2010/02/reporting-as-a-metaphor.html
Whats your Metaphor?
View the full article