Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to get the inner xml for the string given bleow
XML
<owl:Thing rdf:about="#CarAdsIns1">
  <hasMake rdf:resource="#MakeIns1"/>
  <hasModel rdf:resource="#ModelIns1"/>
  <hasYear rdf:resource="#YearIns1"/>
  <hasMileage rdf:resource="#MileageIns1"/>
  <hasPrice rdf:resource="#PriceIns1"/>
  <hasPhoneNr rdf:resource="#PhoneNrIns1"/>
</owl:Thing>

code is:
C#
private void button1_Click(object sender, EventArgs e)
{
  string s = textBox1.Text;
  XmlDocument xml = new XmlDocument();
  xml.LoadXml(s); // suppose that myXmlString contains "<names>...</names>"

  XmlNodeList xnList = xml.SelectNodes("/owl:Thing");
  foreach (XmlNode xn in xnList)
  {
    textBox1.Text = textBox1.Text + Environment.NewLine + xml.DocumentElement.InnerXml;
  }
}

but when i am runnign this code m getting error:
owl is an undeclared prefix.

how can i get this inner text.
Posted
Updated 7-Jun-15 1:13am
v2
Comments
InbarBarkai 7-Jun-15 7:00am    
That's because owl is an undeclare prefix (at least by what you shared with us).
If you are using a namespace in xml you need to declare on it somewhere.
The xml you've posted has no declaration of owl.
Afzaal Ahmad Zeeshan 7-Jun-15 7:35am    
You missed XML namespace somewhere, or probably missed it while copy-pasting the code?

The answer is simple: what you call XML is not XML. A fragment of valid XML is not XML.

To understand this error, you need to understand how XML namespaces work. Here, you have the "prefix not bound with namespace" situation. You need the namespace declarations, such as
HTML
<rdf:RDF 
    xmlns     ="http://www.w3.org/TR/2004/REC-owl-guide-20040210/wine#" 
    xmlns:owl ="http://www.w3.org/2002/07/owl#"
    xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    ...
>
   <!- ... -->
</rdf:RDF>

Please see: http://www.w3.org/TR/owl-guide[^].

Note that prefixes themselves means nothing, the can be any valid unique prefix names matching namespace declarations. Please see:
http://www.w3.org/TR/REC-xml-names[^].

—SA
 
Share this answer
 
v2
Comments
Maciej Los 7-Jun-15 14:47pm    
+5!
Sergey Alexandrovich Kryukov 7-Jun-15 15:09pm    
Thank you, Maciej.
—SA
To read owl data, you need to create proper objects using API. Here is a documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900