0

my language is asp.net. and I use Linq to parsing xml file. but this xml file have set namespace. before load xml file. I try to import xml namespace. but still can't parsing xml correctly.

Imports <xmlns="abc">

<html>
<head>
<title>Do-Life</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../img/css.css" rel="stylesheet" type="text/css">
<script runat="server">
Sub Page_Load(ByVal sender as Object, ByVal e as System.EventArgs)
    If not isPostBack Then
....
Dim TYPINFO As XElement = XElement.Load(server.MapPath(filename))
    Dim tinfos As IEnumerable(Of XElement)      
    tinfos = From tf In TYPINFO...<typhinfo> Select tf
....
....    

xml file:

<?xml version="1.0" encoding="UTF-8"?>
<cwbtyphfcst xmlns="abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cwb.wfc.typhoonfcstCE/namespace typhooninfor.xsd">
<announcement>
    ...
3
  • @JohnSaunders, I have put on the code. Commented Feb 18, 2013 at 7:08
  • @user6919 your XML must have an 'ns' namespace in there. Please show the full XML. Commented Feb 18, 2013 at 7:36
  • @JohnSaunders when I remove 'ns' for the default namespaceprefix, I still can't parsing xml correctly. Do you know why? Thanks. Commented Feb 18, 2013 at 7:52

1 Answer 1

1

I have know the issue.

If I modify the xml content as

<?xml version="1.0" encoding="UTF-8"?>
<cwbtyphfcst xmlns:ns="abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cwb.wfc.typhoonfcstCE/namespace typhooninfor.xsd">
<announcement>
...

identify the namespace prefix name as "ns"

and import the namespace as

Imports <xmlns:ns="abc">

finally, linq is work everything.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.