Jump to content

XML Namespace?


Recommended Posts

HI,

I'm trying to create a program that will make podcast XML files for me. I am able to make nodes, and delete nodes as I get new episodes.

My one issue is with an XML tag with a colon, i.e. "dc:creator" or "itunes:summary"

whenever I try to make a child node with a colon in it I get an error "Reference to undeclared namespace prefix: 'dc'"

there is a namespace listed at the beginning of the file

<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">

I am new to XML files and don't understand the structure fully.

Thanks,

Chris

Link to comment
Share on other sites

Here is an example of the XML file

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>Title of Podcast</title>
    <link>http://www.organization.org</link>
    <description>Something describing podcast</description>
     <itunes:summary>Weekly updates from you-know-who</itunes:summary>
     <itunes:subtitle>Hear what you are missing</itunes:subtitle>
    <itunes:category text=""></itunes:category>
    <language>en-us</language>
    <copyright>2008. All rights reserved.</copyright>
    <pubDate>Sun, 28 Sep 2008 09:27:00 GMT</pubDate>
    <lastBuildDate>Sun, 28 Sep 2008 09:27:00 GMT</lastBuildDate>
    <generator>ToeCaster</generator>
    <managingEditor>chris@nowheres.us(Chris Toews)</managingEditor>
    <webMaster>chris@nowhere.us</webMaster>
    <image>
    <url>http://organization.org/pic.jpg</url>
    <title>Title of pic</title>
    <link>http://www.organization.org</link>
    <width>0</width>
    <height>0</height>
    </image>
    <itunes:owner>
      <itunes:name>who</itunes:name>
      <itunes:email>email</itunes:email>
    </itunes:owner>
    <itunes:author>the author</itunes:author>
    <itunes:explicit>no</itunes:explicit>
    <ttl>1</ttl>
    <item>
      <title>First title</title>
      <link>http://www.organization.org/first.mp3</link>
      <comments>http://www.organization.org/first.mp3</comments>
      <itunes:author>author</itunes:author>
      <dc:creator>Creator</dc:creator>
      <description>9-28-08</description>
      <pubDate>Sun, 28 Sep 2008 09:27:00 GMT</pubDate>
      <itunes:subtitle></itunes:subtitle>
      <itunes:summary></itunes:summary>
      <itunes:keywords></itunes:keywords>
      <itunes:duration>0:0:0</itunes:duration>
      <enclosure url="http://www.organization.org/first.mp3" length="0" type="audio/mpeg" />
      <guid>http://www.organization.org/first.mp3</guid>
      <itunes:explicit>no</itunes:explicit>
    </item>
    <item>
      <title>second title</title>
      <link>http://www.organization.org/second.mp3</link>
      <comments>http://www.organization.org/second.mp3</comments>
      <itunes:author>author</itunes:author>
      <dc:creator>Creator</dc:creator>
      <description>9-28-08</description>
      <pubDate>Sun, 28 Sep 2008 09:27:00 GMT</pubDate>
      <itunes:subtitle></itunes:subtitle>
      <itunes:summary></itunes:summary>
      <itunes:keywords></itunes:keywords>
      <itunes:duration>0:0:0</itunes:duration>
      <enclosure url="http://www.organization.org/second.mp3" length="0" type="audio/mpeg" />
      <guid>http://www.organization.org/second.mp3</guid>
      <itunes:explicit>no</itunes:explicit>
    </item>
  </channel>
</rss>
Edited by cdtoews
Link to comment
Share on other sites

This seems to be the only way:

#include "..\_XMLDomWrapper.au3"
#include <Array.au3>

$sXMLFile = "itunes.xml"

$result = _XMLFileOpen($sXMLFile, 'xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"')
If $result = 0 Then 
    MsgBox(0,"","File not found")
    Exit
EndIf

_XMLCreateChildNode ("//channel", "item", "")
_XMLCreateChildNode ("//channel/item[last()]", "title", "Third title")
_XMLCreateChildNode ("//channel/item[last()]", "itunes:author", "weaponx", "itunes")
_XMLCreateChildNode ("//channel/item[last()]", "dc:creator", "weaponx", "dc")

;Show most recently added item title
$result = _GetFirstValue("//channel/item[last()]/title")
If @ERROR Then
    ConsoleWrite("@ERROR: " & @ERROR & @CRLF)
Else
    ConsoleWrite($result & @CRLF)
EndIf

;_XMLDeleteAttr("//channel/item[3]/itunes:author", "xmlns:itunes")

;_XMLGetValue returns an array (not sure why) this will return the first element
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc

Result:

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>Title of Podcast</title>
    <link>http://www.organization.org</link>
    <description>Something describing podcast</description>
    <itunes:summary>Weekly updates from you-know-who</itunes:summary>
    <itunes:subtitle>Hear what you are missing</itunes:subtitle>
    <itunes:category text=""></itunes:category>
    <language>en-us</language>
    <copyright>2008. All rights reserved.</copyright>
    <pubDate>Sun, 28 Sep 2008 09:27:00 GMT</pubDate>
    <lastBuildDate>Sun, 28 Sep 2008 09:27:00 GMT</lastBuildDate>
    <generator>ToeCaster</generator>
    <managingEditor>chris@nowheres.us(Chris Toews)</managingEditor>
    <webMaster>chris@nowhere.us</webMaster>
    <image>
      <url>http://organization.org/pic.jpg</url>
      <title>Title of pic</title>
      <link>http://www.organization.org</link>
      <width>0</width>
      <height>0</height>
    </image>
    <itunes:owner>
      <itunes:name>who</itunes:name>
      <itunes:email>email</itunes:email>
    </itunes:owner>
    <itunes:author>the author</itunes:author>
    <itunes:explicit>no</itunes:explicit>
    <ttl>1</ttl>
    <item>
      <title>First title</title>
      <link>http://www.organization.org/first.mp3</link>
      <comments>http://www.organization.org/first.mp3</comments>
      <itunes:author>author</itunes:author>
      <dc:creator>Creator</dc:creator>
      <description>9-28-08</description>
      <pubDate>Sun, 28 Sep 2008 09:27:00 GMT</pubDate>
      <itunes:subtitle></itunes:subtitle>
      <itunes:summary></itunes:summary>
      <itunes:keywords></itunes:keywords>
      <itunes:duration>0:0:0</itunes:duration>
      <enclosure url="http://www.organization.org/first.mp3" length="0" type="audio/mpeg"/>
      <guid>http://www.organization.org/first.mp3</guid>
      <itunes:explicit>no</itunes:explicit>
    </item>
    <item>
      <title>second title</title>
      <link>http://www.organization.org/second.mp3</link>
      <comments>http://www.organization.org/second.mp3</comments>
      <itunes:author>author</itunes:author>
      <dc:creator>Creator</dc:creator>
      <description>9-28-08</description>
      <pubDate>Sun, 28 Sep 2008 09:27:00 GMT</pubDate>
      <itunes:subtitle></itunes:subtitle>
      <itunes:summary></itunes:summary>
      <itunes:keywords></itunes:keywords>
      <itunes:duration>0:0:0</itunes:duration>
      <enclosure url="http://www.organization.org/second.mp3" length="0" type="audio/mpeg"/>
      <guid>http://www.organization.org/second.mp3</guid>
      <itunes:explicit>no</itunes:explicit>
    </item>
    <item>
      <title>Third title</title>
      <itunes:author xmlns:itunes="itunes">weaponx</itunes:author>
      <dc:creator xmlns:dc="dc">weaponx</dc:creator>
    </item>
  </channel>
</rss>
Edited by weaponx
Link to comment
Share on other sites

That seems to put an extra "xmlns:itunes" in the xml file. Is this normal, does it matter if it is there? should I be concerned?

Or is that just the format for an XML file?

<itunes:author xmlns:itunes="itunes">weaponx</itunes:author>

<dc:creator xmlns:dc="dc">weaponx</dc:creator>

Link to comment
Share on other sites

That seems to put an extra "xmlns:itunes" in the xml file. Is this normal, does it matter if it is there? should I be concerned?

Or is that just the format for an XML file?

<itunes:author xmlns:itunes="itunes">weaponx</itunes:author>

<dc:creator xmlns:dc="dc">weaponx</dc:creator>

Yea you can see I commented out an attempt to remove it. I think its something the XML COM object adds for Internet Explorer compatibility. I think it is okay to leave it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...