Solved

dtd and xml not jiving

Posted on 2011-03-03
5
329 Views
Last Modified: 2012-05-11
So I have an xml feed that I am getting from another system and so I created a dtd as part of the mapping process on my end.  However right now they dont like each other.  I have been starring at this for a while and I need to see if someone can point out the error of my ways.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ItemInquiry SYSTEM "ItemInquiry.dtd" > 
<ItemInquiry> 
<Code="7VQ"  Item="ST4006"  Dollars="228.00"  Error="S" /> 
<Code="XXX"  Item="6444.54"  Dollars="44.95"  Error="X" /> 
<Code="QFY"  Item"ST2753D"  Dollars="228.00"  Error=" " /> 
<Code="WTF"  Item="ST4006"  Dollars="168.00"  Error=" " /> 
</ItemInquiry> 


<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ItemInquiry ( Code | Item | Dollars | Error )* >
<!ELEMENT Code ( #PCDATA ) >
<!ELEMENT Item ( #PCDATA ) >
<!ELEMENT Dollars ( #PCDATA ) >
<!ELEMENT Error ( #PCDATA ) >

Open in new window

0
Comment
Question by:iceman19330
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35026940
well, your XML is not wellformed,
you seem to have only attributes and no element name
You could rather mean something like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ItemInquiry SYSTEM "ItemInquiry.dtd" > 
<ItemInquiry>
<Item Code="7VQ"  Name="ST4006"  Dollars="228.00"  Error="S" />
<Item Code="XXX"  Name="6444.54"  Dollars="44.95"  Error="X" />
<Item Code="QFY"  Name"ST2753D"  Dollars="228.00"  Error=" " />
<Item Code="WTF"  Name="ST4006"  Dollars="168.00"  Error=" " />
</ItemInquiry>


0
 

Author Comment

by:iceman19330
ID: 35026964
what would the dtd look like?

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ItemInquiry ( Code | Name | Dollars | Error )* >
<!ELEMENT Code ( #PCDATA ) >
<!ELEMENT Name ( #PCDATA ) >
<!ELEMENT Dollars ( #PCDATA ) >
<!ELEMENT Error ( #PCDATA ) >
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 35026969
Having this as XML

<ItemInquiry>
    <Item Code="7VQ"  Name="ST4006"  Dollars="228.00"  Error="S" />
    <Item Code="XXX"  Name="6444.54"  Dollars="44.95"  Error="X" />
    <Item Code="QFY"  Name="ST2753D"  Dollars="228.00"   />
    <Item Code="WTF"  Name="ST4006"  Dollars="168.00"   />
</ItemInquiry>

This would be the DTD
<!ELEMENT ItemInquiry ( Item )* >
<!ELEMENT Item EMPTY  >
<!ATTLIST Item 
    Code CDATA #REQUIRED 
    Name CDATA #REQUIRED 
    Dollars CDATA #REQUIRED 
    Error (S | X ) #IMPLIED >

Open in new window

0
 

Author Comment

by:iceman19330
ID: 35027098
Thank you for the promptness and throughness of your answer.

Now with the Error do I just need to list the possible flags that come back in the DTD and if there is no flag then its blank but I dont need to do anything with that blank spot in the DTD?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35027463
Ah, the blank spot, You can't express the blank spot in a finite list
I made the attribute implied, so you can leave it out as an alternative to a blank spot
If you can't leave the attribute out as an alternative, you need to make it CDATA as the rest

   Error CDATA  #REQUIRED >
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert XML to excel12book 5 31
Shredding xml into an oracle 11g Database 2 58
XML extra information 8 28
I dont know why my code is no longer working help please 9 62
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question