473,324 Members | 2,501 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,324 software developers and data experts.

SetAttribute xlink:href

Hello all,

I am having difficulty figuring out how to create an XmlElement and giving
it an attribute that requires a namespace. Here is what I have so far which
throws an exception because you can't have a : in an attribute name???

XmlElement eOnlineResource = m_context.CreateElement("OnlineResource");

eOnlineResource.SetAttribute("xlink:href", "http://www.w3c.org/1999/xlink",
sldUrl);

Any help is appreciated.
Aug 22 '06 #1
4 4726
See: http://www.dotnet247.com/247referenc...43/216508.aspx

-------------------------------------------------------------------------------------------------------------
Dim xdoc As New XmlDocument
Dim eOnlineResource As XmlElement

xdoc.LoadXml("<root xmlns='DefaultNSDickster'
xmlns:xlink='http://www.w3c.org/1999/xlink'></root>")

eOnlineResource =
xdoc.CreateElement("eOnLineResource","DefaultNSDic kster")

eOnlineResource.SetAttribute("href",
"http://www.w3c.org/1999/xlink", "theValue")

xdoc.FirstChild.AppendChild(eOnlineResource)

-------------------------------------------------------------------------------------------------------------

The prefix will be in the XML.

Dickster

Aug 22 '06 #2
Thanks but that still doesn't work. I think it has to do with the fact that
I am operating on a node and not a document. Here is my code:

XmlNode sldUrlNode =
layerNode.SelectSingleNode("StyleList/Style/SLD/OnlineResource");

if (sldUrlNode == null)
{
// we need to create the SLD Node if it does not exist
XmlElement eStyleList =
m_context.CreateElement("StyleList");

XmlElement eStyle = m_context.CreateElement("Style");
eStyle.SetAttribute("current", "1");

eStyleList.AppendChild(eStyle);

XmlElement eSLD = m_context.CreateElement("SLD");

XmlElement eName = m_context.CreateElement("Name");
eName.InnerText = layerName;

eSLD.AppendChild(eName);

XmlElement eOnlineResource =
m_context.CreateElement("OnlineResource", "xlink");

eOnlineResource.SetAttribute("href",
"http://www.w3.org/1999/xlink", sldUrl);

eSLD.AppendChild(eOnlineResource);

eStyle.AppendChild(eSLD);

layerNode.AppendChild(eStyleList);

}
else
{

sldUrlNode.Attributes[0].Value = sldUrl;
}
}
}
"dickster" wrote:
See: http://www.dotnet247.com/247referenc...43/216508.aspx

-------------------------------------------------------------------------------------------------------------
Dim xdoc As New XmlDocument
Dim eOnlineResource As XmlElement

xdoc.LoadXml("<root xmlns='DefaultNSDickster'
xmlns:xlink='http://www.w3c.org/1999/xlink'></root>")

eOnlineResource =
xdoc.CreateElement("eOnLineResource","DefaultNSDic kster")

eOnlineResource.SetAttribute("href",
"http://www.w3c.org/1999/xlink", "theValue")

xdoc.FirstChild.AppendChild(eOnlineResource)

-------------------------------------------------------------------------------------------------------------

The prefix will be in the XML.

Dickster

Aug 22 '06 #3


jvanulden wrote:
I am having difficulty figuring out how to create an XmlElement and giving
it an attribute that requires a namespace. Here is what I have so far which
throws an exception because you can't have a : in an attribute name???

XmlElement eOnlineResource = m_context.CreateElement("OnlineResource");

eOnlineResource.SetAttribute("xlink:href", "http://www.w3c.org/1999/xlink",
sldUrl);
This should help:

XmlDocument xmlDocument = new XmlDocument();
XmlElement eOnlineResource =
xmlDocument.CreateElement("OnlineResource");
XmlAttribute xlinkHref = xmlDocument.CreateAttribute("xlink",
"href", "http://www.w3.org/1999/xlink");
xlinkHref.Value = "http://example.com/example";
eOnlineResource.SetAttributeNode(xlinkHref);

For the attribute value you obviously want your sldUrl then instead of
the example.com URL the example shows.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 22 '06 #4
Thanks Martin, that worked!

"Martin Honnen" wrote:
>

jvanulden wrote:
I am having difficulty figuring out how to create an XmlElement and giving
it an attribute that requires a namespace. Here is what I have so far which
throws an exception because you can't have a : in an attribute name???

XmlElement eOnlineResource = m_context.CreateElement("OnlineResource");

eOnlineResource.SetAttribute("xlink:href", "http://www.w3c.org/1999/xlink",
sldUrl);

This should help:

XmlDocument xmlDocument = new XmlDocument();
XmlElement eOnlineResource =
xmlDocument.CreateElement("OnlineResource");
XmlAttribute xlinkHref = xmlDocument.CreateAttribute("xlink",
"href", "http://www.w3.org/1999/xlink");
xlinkHref.Value = "http://example.com/example";
eOnlineResource.SetAttributeNode(xlinkHref);

For the attribute value you obviously want your sldUrl then instead of
the example.com URL the example shows.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: eagle0Nine | last post by:
I'm fairly new at using XML XSL and XLink, and I was wondering how I could use the three to create a menu link to another page (i.e. a menu button "Contact Us" would link to a seperate contact...
1
by: Bernd Oninger | last post by:
As far as I know one could use other xsd schemas with the import and the xlink feature. What are the differences (beside the syntax)? Bernd
0
by: Gene Ellis | last post by:
Very simple question. If I have the XML file below: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="newspage.xsl"?> <newspage> <content>Click here for blah...
4
by: Lance Dyas | last post by:
I have managed to get the xml to load using the xmlHTTPrequest... (inspite of premature readyState 4) the problem now arises in Safari alone... var thelink = node.getAttribute("xlink:href") ...
2
by: adMjb | last post by:
Hi Any help would be fantastic I have a simple problem but I cant work it out... DOHH...., this is my XML: <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet type="text/css"...
4
by: Martin | last post by:
Hello I'm trying to learn xlink/xpointer (with no success so far :-( I would like to produce the following output. AAAA BBBB CCCC AAAA
0
by: ab.angadbhat | last post by:
hi, I have an element in the xml file which has xlink:href ="xyz.xml" as an attribute. I am using xpointer to point to only 2nd <Uelement of the xyz.xml file and so i am doing:- xlink:href...
1
by: kaye80 | last post by:
I have an XML and XSL document. I am trying to incorporate hyperlinks throughout the XML document. I have read many of the related posts on this and other forums but I can't seem to get it right. ...
0
by: osin | last post by:
Hello everyone, I need to generate an XML file whose element would be an active link (triggering a PERL script). The only tool I've found which is capable of doing it is Xlink. The problem is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.