DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Very basic XML question

  1. #1
    Join Date
    May 2004
    Posts
    6

    Very basic XML question

    Can anyone explain the XML notation in the following code that uses a ":"
    I am trying to parse this XML to access the values in <domain:name> but my script blows up when I try to access values by name. I get this error:
    "Prefix must resolve to a namespace: domain"
    Or can anyone point me to an explanation on the web of this naming syntax? (

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd"> <command>
    <check>
    <domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0" xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
    <domain:name>example1.tld</domain:name>
    <domain:name>example2.tld</domain:name>
    <domain:name>example3.tld</domain:name>
    </domain:check>
    </check>
    <unspec/>
    <clTRID>ABC-12346</clTRID>
    </command>
    </epp>

  2. #2
    Join Date
    May 2004
    Posts
    103
    What you are showing is XML as it is written to avoid element conflicts. A common example is two XML documents that could/would be merged, but a common element between the two is the element <table>. BUT, in one XML document this element describes an HTML table, while in the other document the element describes furniture. The tags would have to be rewritten with the prefix (as you state, the <describe:name> to avoid an element collision. When this is done, a unique namespace must be used with the element to provide a 'qualified name' with a unique namespace.

    A very good web site to get a more clear understanding is w3schools.com. The exact page on namespaces is: http://www.w3schools.com/xml/xml_namespaces.asp

    Rather than:

    This XML document carries information in a table:

    <table>
    <tr>
    <td>Apples</td>
    <td>Bananas</td>
    </tr>
    </table>

    This XML document carries information about a table (a piece of furniture):

    <table>
    <name>African Coffee Table</name>
    <width>80</width>
    <length>120</length>
    </table>

    This would be done.
    ------------------------------------------------------------------
    This XML document carries information in a table:

    <h:table xmlns:h="http://www.w3.org/TR/html4/">
    <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
    </h:tr>
    </h:table>

    This XML document carries information about a piece of furniture:

    <f:table xmlns:f="http://www.w3schools.com/furniture">
    <f:name>African Coffee Table</f:name>
    <f:width>80</f:width>
    <f:length>120</f:length>
    </f:table>

    These 2 tables could now be used in the same XML document without problem.

  3. #3
    Join Date
    May 2004
    Posts
    6

    Thanks

    Thanks. That is a clear explanation.
    However I find the error message confusing.
    "Prefix must resolve to a namespace: domain"
    If "domain:name" is referenced, does that mean that the schema must also have the same namespace?

  4. #4
    Join Date
    May 2004
    Posts
    103
    Yes.

    I have only worked with DTDs so far, which is a form of schema, but if you were to use a regular XML schema I don't doubt you'd have to declare it just as you would in a DTD.

    To use the same example, this is how to incorporate qualifying names into the same document when they use elements that have the same decriptive word but mean different things.

    I supplied a 'root' element of "tables", which has two children: h:table and f:table. The 'h' and the 'f' are the prefixes. The element names are attached, qualified with the prefix and namespace value. The qualified name (prefix with element name) are declared along with the value in the DTD.

    Although a DTD is a form of schema, which is one of the two choices (either DTD or XML schema) for defining an XML document, how to define in a regular XML schema is something you'd need to investigate further, if in fact it's not a DTD you are dealing with.

    <?xml version="1.0"?>
    <!DOCTYPE tables [
    <!ELEMENT tables (h:table, f:table)>
    <!ELEMENT h:table (h:tr)>
    <!ATTLIST h:table xmlns:h CDATA #FIXED "http://www.w3.org/TR/html4/">
    <!ELEMENT h:tr (h:td+)>
    <!ELEMENT h:td (#PCDATA)>
    <!ELEMENT f:table (f:name, f:width, f:length)>
    <!ATTLIST f:table xmlns:f CDATA #FIXED "http://www.w3schools.com/furniture">
    <!ELEMENT f:name (#PCDATA)>
    <!ELEMENT f:width (#PCDATA)>
    <!ELEMENT f:length (#PCDATA)>
    ]>
    <tables>
    <h:table xmlns:h="http://www.w3.org/TR/html4/">
    <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
    </h:tr>
    </h:table>

    <f:table xmlns:f="http://www.w3schools.com/furniture">
    <f:name>African Coffee Table</f:name>
    <f:width>80</f:width>
    <f:length>120</f:length>
    </f:table>

    </tables>
    Last edited by coveyte; 06-04-2004 at 12:20 PM.

  5. #5
    Join Date
    May 2004
    Posts
    6

    Thanks again

    This confirms what I thought. It seems that the <domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0" xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
    does not contain the element domain:name

  6. #6
    Join Date
    May 2004
    Posts
    103
    Your example is:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd"> <command>
    <check>
    <domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0" xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
    <domain:name>example1.tld</domain:name>
    <domain:name>example2.tld</domain:name>
    <domain:name>example3.tld</domain:name>
    </domain:check>
    </check>
    <unspec/>
    <clTRID>ABC-12346</clTRID>
    </command>
    </epp>

    The <domain:check> parent tag DOES contain the prefix/element of <domain:name> but it needs to be qualified in the DTD or schema.

    Since the DTD or schema actually 'say' what your tags and attributes mean, this would account for the problem you are having. You have the prefix/element name with namespace, but nothing to state what it all means.

    Qualifying those prefix/element names in the schema will eliminate your problem.
    Last edited by coveyte; 06-04-2004 at 12:49 PM.

  7. #7
    Join Date
    May 2004
    Posts
    6

    local dtd or xsd

    Since I have no control of the public schema, I have to make sure the XML template sent to me agrees with the schema, not the other way around?

    Since you are being so helpful, can you tell me how I refer to a dtd or xsd file in the same folder as the script?

    <epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">

    <domain:check xmlns:domain="urn:iana:xml:ns:domain-1.0" xsi:schemaLocation="urn:iana:xml:ns:domain-1.0 domain-1.0.xsd">
    Both of these refer to external schema.
    Can I say <domain:check xmlns:domain="urn:domain-1.0" xsi:schemaLocation="urn:domain-1.0 domain-1.0.xsd"> to refer to a test xsd file ?

  8. #8
    Join Date
    May 2004
    Posts
    103
    I don't think I have enough information. Was this sent to you as part of your job? There are schema locations stated here, along with namespaces, so this document must have validated against the schema before being sent to you. This means that different prefixes should have been assigned in the schema, which would qualify the tags, and therefore the document would validate.

    I just don't know enough information to know why the script you refer to isn't working as wished. I'd want to look at the schema, myself, to make sure a 'domain' prefix is qualifying elements.

    I'm not familiar with the format of the paths to the files, otherwise I'd try getting it through a browser. I'm thinking this is a local file, local to where the file originated from, and therefore your file might not be accessing it. You'd have problems with your file validating then, and henseforth script problems...

    How about getting a copy of the schema from whoever give you the XML file, link it locally on your machine to your XML file, and then try working with the script?

    The location of this schema uses a URN. URNs are persistent identifiers for information resources, so to me it looks like your XML file isn't accessing the schema since a relative or absolute URL isn't be used.

    I think this is about all I can say about this, until more information was supplied. You need the existent schema, local to your XML file, in order to see how things work.

  9. #9
    Join Date
    May 2004
    Posts
    6

    Thanks again for all your time.

    I was tring to develop a script using an XML parser. The xml code is from http://epp-rtk.sourceforge.net/epp-howto.html and is the first example of XML that would be passed to a domain registry.
    The schema is from http://www.iana.org/assignments/xml-...domain-1.0.xsd
    as far as I can tell - though I haven't figured out how to parse a urn.
    It includes
    <element name="check" type="domain:mNameType" />
    Then lower down:
    <complexType name="mNameType">
    - <sequence>
    <element name="name" type="eppcom:labelType" maxOccurs="unbounded" />
    </sequence>
    </complexType>
    I don't know if this qualifies as a defined namespace, though I suspect it does...

  10. #10
    Join Date
    May 2004
    Posts
    103
    I think you've got your hands full if you really want to use that XML code. The Web page has it just planted in an HTML page, and there is no indication that a schema even exists for it. The URL you provided for the schema file doesn't go to the XML code you display here. It goes to another XML file. The directory for these can be found http://www.iana.org/assignments/xml-registry/schema/ and you will see that there is an XML page with the same name as the schema file. The tags to both documents match up, but the tags don't match up with the code pasted in the HTML page, the same code you'd like to work with. To me, it looks like the complete page of XML would have to be put together, and THEN the schema or DTD created for it. For some people a schema might be easier, but it would be easy enought to create a DTD.

    The URN can't be parsed. It's used more for searching, as there can be only one document with that unique name. Kind of like a 'copyright' on the document with relating document name.

    I'm sorry I can't help you more on this, but I must say, you've really got the energy even to tackle this.
    Last edited by coveyte; 06-04-2004 at 05:43 PM.

  11. #11
    Join Date
    May 2004
    Posts
    6

    --

    Thanks again.
    You have enlightened me on various matters. I have found some tutorials and I am getting educated. It seems the XML I used was strictly a suggestion on a template type.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center